@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.12);
  --primary-glow: rgba(99, 102, 241, 0.3);
  --accent: #f472b6;

  /* Question Status */
  --q-not-visited: #64748b;
  --q-not-answered: #ef4444;
  --q-answered: #22c55e;
  --q-marked: #a855f7;
  --q-answered-marked: #f59e0b;

  /* Semantic */
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;

  /* Dimensions */
  --header-h: 60px;
  --bottom-h: 60px;
  --sidebar-w: 270px;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-2xl: 32px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-normal: 0.25s ease;
  --t-slow: 0.4s ease;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.15);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.2);
  --shadow-xl: 0 16px 56px rgba(0,0,0,0.28);
}

/* ============================================
   DARK THEME
   ============================================ */
[data-theme="dark"] {
  --bg:          #0b0d1a;
  --bg-2:        #111326;
  --card:        #181b2e;
  --card-2:      #1f2340;
  --card-hover:  #252950;
  --border:      rgba(255,255,255,0.07);
  --border-2:    rgba(255,255,255,0.12);
  --text-1:      #f1f5f9;
  --text-2:      #94a3b8;
  --text-3:      #64748b;
  --glass:       rgba(24, 27, 46, 0.85);
  --option-bg:   #1f2340;
  --option-sel:  rgba(99,102,241,0.18);
  --sidebar-bg:  #111326;
  --modal-dim:   rgba(0,0,0,0.75);
}

/* ============================================
   LIGHT THEME
   ============================================ */
[data-theme="light"] {
  --bg:          #eef2ff;
  --bg-2:        #e0e7ff;
  --card:        #ffffff;
  --card-2:      #f5f7ff;
  --card-hover:  #eef2ff;
  --border:      rgba(0,0,0,0.07);
  --border-2:    rgba(0,0,0,0.13);
  --text-1:      #0f172a;
  --text-2:      #475569;
  --text-3:      #94a3b8;
  --glass:       rgba(255,255,255,0.9);
  --option-bg:   #f8faff;
  --option-sel:  rgba(99,102,241,0.09);
  --sidebar-bg:  #f0f4ff;
  --modal-dim:   rgba(0,0,0,0.45);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--t-normal), color var(--t-normal);
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
img { max-width: 100%; height: auto; display: block; }
input[type="checkbox"] { accent-color: var(--q-marked); }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============================================
   BUTTON SYSTEM
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.35rem;
  border-radius: var(--r-md);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--t-fast);
  cursor: pointer;
  border: none;
  white-space: nowrap;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity var(--t-fast);
}
.btn:hover::after { opacity: 0.06; }
.btn:active::after { opacity: 0.12; }

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #fff;
  box-shadow: 0 4px 18px var(--primary-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 25px var(--primary-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-outline {
  background: transparent;
  color: var(--text-2);
  border: 1.5px solid var(--border-2);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.btn-ghost {
  background: var(--card-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--card-hover);
  color: var(--text-1);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 18px rgba(239,68,68,0.3);
}
.btn-danger:hover { transform: translateY(-2px); }

.btn-success {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 18px rgba(34,197,94,0.3);
}
.btn-success:hover { transform: translateY(-2px); }

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
}
.btn-warning:hover { transform: translateY(-2px); }

.btn-sm { padding: 0.38rem 0.9rem; font-size: 0.8rem; border-radius: var(--r-sm); }
.btn-lg { padding: 0.85rem 2rem; font-size: 1rem; border-radius: var(--r-lg); }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--r-md); }

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ============================================
   LOGO / BRAND
   ============================================ */
.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  user-select: none;
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

/* Theme Toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--card-2);
  border: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ============================================
   HOME SCREEN
   ============================================ */
.home-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.home-header {
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 50;
}

.home-main {
  flex: 1;
  padding: 3rem 1.5rem;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

.home-hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(99,102,241,0.25);
  padding: 0.3rem 0.9rem;
  border-radius: var(--r-full);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1.2rem;
}

.home-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  font-weight: 900;
  line-height: 1.15;
  margin-bottom: 1rem;
  letter-spacing: -0.03em;
}

.home-hero h1 .gradient-text {
  background: linear-gradient(135deg, #6366f1 20%, #f472b6 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero p {
  font-size: 1.05rem;
  color: var(--text-2);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.65;
}

/* Upload Area */
.upload-card {
  background: var(--card);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.upload-area {
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  position: relative;
  border: 2px dashed var(--border-2);
  border-radius: var(--r-xl);
  margin: 1.25rem;
  transition: all var(--t-normal);
  background: var(--bg-2);
}

.upload-area::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-xl);
  background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(244,114,182,0.06));
  opacity: 0;
  transition: opacity var(--t-normal);
}

.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
}
.upload-area:hover::before, .upload-area.drag-over::before {
  opacity: 1;
}
.upload-area.drag-over {
  border-style: solid;
  transform: scale(1.01);
}

#fileInput { display: none; }

.upload-icon-wrap {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
  animation: float 3.5s ease-in-out infinite;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 8px 16px rgba(99,102,241,0.35));
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.upload-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  position: relative;
  z-index: 1;
}

.upload-subtitle {
  color: var(--text-2);
  font-size: 0.88rem;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1;
}

.upload-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  padding: 0.6rem 1.75rem;
  border-radius: var(--r-full);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--t-fast);
  box-shadow: 0 4px 18px var(--primary-glow);
  border: none;
  font-family: inherit;
  position: relative;
  z-index: 1;
}
.upload-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 25px var(--primary-glow);
}

.upload-hint {
  margin-top: 0.9rem;
  font-size: 0.78rem;
  color: var(--text-3);
  position: relative;
  z-index: 1;
}

/* Test Preview */
.test-preview {
  padding: 1.5rem 1.75rem 1.75rem;
  display: none;
  animation: slideUp 0.35s ease;
  border-top: 1px solid var(--border);
}

.test-preview.visible { display: block; }

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

.preview-top {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.preview-badge {
  padding: 0.25rem 0.75rem;
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-full     { background: rgba(99,102,241,0.14); color: #818cf8; border: 1px solid rgba(99,102,241,0.25); }
.badge-sectional{ background: rgba(34,197,94,0.14);  color: #4ade80; border: 1px solid rgba(34,197,94,0.25); }

.preview-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
}

.preview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-item {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.85rem 1rem;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
}

.sections-list { margin-bottom: 1.25rem; }

.sections-list-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.65rem;
}

.section-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
}

.section-chip-name { font-weight: 500; }

.section-chip-meta {
  display: flex;
  gap: 1rem;
  color: var(--text-3);
  font-size: 0.78rem;
}

.marking-banner {
  background: var(--primary-light);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--r-md);
  padding: 0.7rem 1rem;
  font-size: 0.84rem;
  color: var(--text-2);
  margin-bottom: 1.5rem;
}
.marking-banner strong { color: var(--primary); }

.preview-actions { display: flex; gap: 0.75rem; }

/* Format Guide */
.format-guide {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.format-guide summary {
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-2);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.format-guide summary::before { content: '📋'; }
.format-guide[open] summary::after { content: ' ▲'; color: var(--text-3); }
.format-guide:not([open]) summary::after { content: ' ▼'; color: var(--text-3); }

.format-guide pre {
  margin-top: 1rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-2);
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  max-height: 380px;
  overflow-y: auto;
}


/* ============================================
   EXAM SCREEN
   ============================================ */
.exam-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* -- Header -- */
.exam-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-2);
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
}

.exam-header-left  { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.exam-header-mid   { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.exam-header-right { display: flex; align-items: center; gap: 0.65rem; flex-shrink: 0; }

.exam-title-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

/* Section Tabs */
.section-tabs {
  display: flex;
  gap: 0.2rem;
  background: var(--bg-2);
  border-radius: var(--r-md);
  padding: 0.2rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.section-tabs::-webkit-scrollbar { display: none; }

.section-tab {
  padding: 0.28rem 0.8rem;
  border-radius: var(--r-sm);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--t-fast);
  color: var(--text-2);
  background: none;
  border: none;
  font-family: inherit;
  white-space: nowrap;
  user-select: none;
}

.section-tab:hover:not(.locked):not(.active) {
  background: var(--card-hover);
  color: var(--text-1);
}

.section-tab.active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.section-tab.locked {
  cursor: not-allowed;
  opacity: 0.35;
}

.section-tab.completed:not(.active) {
  color: var(--success);
}

/* Timer */
.timer-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--card-2);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-full);
  padding: 0.32rem 0.9rem;
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 88px;
  justify-content: center;
  transition: all var(--t-normal);
  letter-spacing: 0.03em;
}

.timer-wrap.warning {
  border-color: var(--warning);
  color: var(--warning);
  background: rgba(245,158,11,0.08);
  animation: timerPulse 1.5s ease infinite;
}

.timer-wrap.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(239,68,68,0.08);
  animation: timerPulse 0.7s ease infinite;
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* -- Exam Body -- */
.exam-body {
  margin-top: var(--header-h);
  margin-bottom: var(--bottom-h);
  display: flex;
  height: calc(100vh - var(--header-h) - var(--bottom-h));
  overflow: hidden;
}

/* Question Panel */
.question-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.question-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}

.q-num-badge {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  padding: 0.25rem 0.75rem;
  border-radius: var(--r-full);
  font-size: 0.78rem;
  font-weight: 800;
}

.mark-review-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-2);
  user-select: none;
  margin-left: auto;
  padding: 0.25rem 0.6rem;
  border-radius: var(--r-full);
  background: var(--card-2);
  border: 1px solid var(--border);
  transition: all var(--t-fast);
}
.mark-review-label:hover { border-color: var(--q-marked); color: var(--q-marked); }
.mark-review-label input { width: 14px; height: 14px; cursor: pointer; }

.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.6rem 1.75rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  animation: qSlide 0.2s ease;
}

@keyframes qSlide {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.question-text {
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--text-1);
  white-space: pre-wrap;
}

.question-image {
  margin-top: 1rem;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  max-width: 480px;
}

/* Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem;
  background: var(--option-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-fast);
  user-select: none;
  position: relative;
}
.option-item:hover {
  border-color: var(--border-2);
  background: var(--card-hover);
  transform: translateX(4px);
}
.option-item.selected {
  background: var(--option-sel);
  border-color: var(--primary);
}

.opt-label {
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1.5px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  flex-shrink: 0;
  transition: all var(--t-fast);
}
.option-item.selected .opt-label {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.opt-text {
  font-size: 0.95rem;
  color: var(--text-1);
  line-height: 1.55;
  flex: 1;
}

/* Result Review States */
.option-item.review-correct {
  background: rgba(34,197,94,0.1);
  border-color: var(--success);
  cursor: default;
}
.option-item.review-correct:hover { transform: none; }
.option-item.review-correct .opt-label {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.option-item.review-wrong {
  background: rgba(239,68,68,0.1);
  border-color: var(--danger);
  cursor: default;
}
.option-item.review-wrong:hover { transform: none; }
.option-item.review-wrong .opt-label {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.option-item.review-default { cursor: default; }
.option-item.review-default:hover { transform: none; }

.opt-answer-tag {
  margin-left: auto;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--r-full);
  flex-shrink: 0;
}
.opt-answer-tag.correct { color: var(--success); }
.opt-answer-tag.wrong   { color: var(--danger); }

/* -- Sidebar -- */
.exam-sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-title {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-section-label {
  padding: 0.5rem 1rem;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.palette-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 1rem;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  align-content: start;
}

.pal-btn {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all var(--t-fast);
  position: relative;
}
.pal-btn:hover { transform: scale(1.1); box-shadow: var(--shadow-md); }
.pal-btn.pal-active {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--primary);
  transform: scale(1.08);
  z-index: 2;
}

.pal-btn.st-not-visited   { background: var(--q-not-visited); }
.pal-btn.st-not-answered  { background: var(--q-not-answered); }
.pal-btn.st-answered      { background: var(--q-answered); }
.pal-btn.st-marked        { background: var(--q-marked); }
.pal-btn.st-answered-marked { background: var(--q-answered-marked); }

.palette-legend {
  border-top: 1px solid var(--border);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.73rem;
  color: var(--text-2);
}
.legend-dot {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}

.sidebar-submit-area {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border-2);
}

/* -- Bottom Bar -- */
.exam-bottom {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 200;
  height: var(--bottom-h);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 0.6rem;
}

.bottom-left, .bottom-right { display: flex; gap: 0.5rem; }

/* -- Modal -- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-dim);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.open { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 2rem;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.88) translateY(-15px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon { font-size: 2.5rem; text-align: center; display: block; margin-bottom: 0.85rem; }
.modal-title { font-size: 1.2rem; font-weight: 800; text-align: center; margin-bottom: 0.65rem; }
.modal-desc  { color: var(--text-2); text-align: center; font-size: 0.88rem; margin-bottom: 1.25rem; line-height: 1.6; }

.modal-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}
.modal-stat {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0.75rem 0.5rem;
  text-align: center;
}
.modal-stat-v {
  font-size: 1.5rem;
  font-weight: 900;
  display: block;
  margin-bottom: 0.15rem;
}
.modal-stat-l { font-size: 0.69rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.modal-stat-v.clr-success { color: var(--success); }
.modal-stat-v.clr-danger  { color: var(--danger); }
.modal-stat-v.clr-muted   { color: var(--text-3); }

.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* -- Toast -- */
.toast {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: var(--card);
  border: 1px solid var(--border-2);
  color: var(--text-1);
  padding: 0.65rem 1.5rem;
  border-radius: var(--r-full);
  font-size: 0.84rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 5000;
  opacity: 0;
  transition: all var(--t-normal);
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================
   RESULT SCREEN
   ============================================ */
.result-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 4rem;
}

.result-hero {
  background: linear-gradient(135deg, #111326 0%, #1d2140 50%, #251840 100%);
  padding: 2.25rem 2rem 4.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

[data-theme="light"] .result-hero {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #9333ea 100%);
}

.result-hero-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.18;
  pointer-events: none;
}
.orb-1 { width: 300px; height: 300px; background: #6366f1; top: -80px; left: -60px; }
.orb-2 { width: 250px; height: 250px; background: #f472b6; bottom: -60px; right: -40px; }

.result-hero-content { position: relative; z-index: 1; }

.result-complete-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(34,197,94,0.15);
  color: #4ade80;
  border: 1px solid rgba(34,197,94,0.25);
  padding: 0.35rem 1rem;
  border-radius: var(--r-full);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.9rem;
}

.result-test-name {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 800;
  color: #fff;
  margin-bottom: 0.35rem;
  letter-spacing: -0.02em;
}

.result-test-meta { color: rgba(255,255,255,0.55); font-size: 0.86rem; }

/* Score Section */
.result-body {
  max-width: 980px;
  margin: -2.5rem auto 0;
  padding: 0 1.25rem;
  width: 100%;
}

.score-main-card {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 2rem;
  box-shadow: var(--shadow-xl);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 2rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.score-dial-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.score-dial {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: conic-gradient(var(--primary) calc(var(--pct) * 1%), var(--card-2) 0%);
  transition: background 1s ease;
}
.score-dial::before {
  content: '';
  position: absolute;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--card);
}
.score-dial-inner {
  position: relative;
  z-index: 1;
  text-align: center;
}
.score-number-big {
  font-size: 1.65rem;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  display: block;
  letter-spacing: -0.03em;
}
.score-out-of { font-size: 0.72rem; color: var(--text-3); font-weight: 600; display: block; margin-top: 0.15rem; }
.score-dial-label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); text-align: center; }

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

.score-stat-box {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1rem;
  text-align: center;
  transition: all var(--t-fast);
}
.score-stat-box:hover {
  border-color: var(--border-2);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.score-stat-val {
  font-size: 1.65rem;
  font-weight: 900;
  display: block;
  margin-bottom: 0.2rem;
  letter-spacing: -0.03em;
}
.score-stat-lbl { font-size: 0.7rem; color: var(--text-3); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }

/* Section Title */
.section-title-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 1rem;
  margin-top: 0.25rem;
}
.section-title-bar::before {
  content: '';
  width: 4px;
  height: 1.1rem;
  background: linear-gradient(180deg, #6366f1, #8b5cf6);
  border-radius: 2px;
  flex-shrink: 0;
}

/* Breakdown Table */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.75rem;
}
.breakdown-table th {
  background: var(--card-2);
  padding: 0.85rem 1.2rem;
  text-align: left;
  font-size: 0.73rem;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-2);
}
.breakdown-table td {
  padding: 0.85rem 1.2rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.breakdown-table tr:last-child td { border-bottom: none; }
.breakdown-table tr:hover td { background: var(--card-2); }

/* Question Review */
.review-section-group { margin-bottom: 1.75rem; }

.review-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, rgba(99,102,241,0.09), rgba(139,92,246,0.09));
  border: 1px solid rgba(99,102,241,0.18);
  border-radius: var(--r-md);
  padding: 0.7rem 1.1rem;
  margin-bottom: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
}
.review-section-header span:last-child { font-weight: 500; color: var(--text-3); font-size: 0.78rem; }

.review-q-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 1.35rem 1.5rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.review-q-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.review-q-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-3);
  background: var(--card-2);
  padding: 0.2rem 0.6rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--r-full);
  font-size: 0.73rem;
  font-weight: 800;
}
.status-badge.correct     { background: rgba(34,197,94,0.13);  color: var(--success); }
.status-badge.wrong       { background: rgba(239,68,68,0.13);  color: var(--danger); }
.status-badge.unattempted { background: rgba(100,116,139,0.13);color: var(--text-3); }

.solution-toggle-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(99,102,241,0.22);
  padding: 0.25rem 0.75rem;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--t-fast);
  font-family: inherit;
}
.solution-toggle-btn:hover {
  background: rgba(99,102,241,0.2);
}

.review-q-text {
  font-size: 0.96rem;
  line-height: 1.7;
  margin-bottom: 0.9rem;
  color: var(--text-1);
  white-space: pre-wrap;
}

.solution-box {
  margin-top: 0.85rem;
  padding: 1rem 1.1rem;
  background: rgba(99,102,241,0.06);
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: var(--r-md);
  font-size: 0.87rem;
  color: var(--text-2);
  line-height: 1.75;
  display: none;
}
.solution-box.open { display: block; animation: slideUp 0.25s ease; }
.solution-box-title {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Result Actions */
.result-action-bar {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
  margin-bottom: 2rem;
}

/* ============================================
   INPUT TABS (Upload / Paste)
   ============================================ */
.input-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-2);
  padding: 0 1.25rem;
  background: var(--card-2);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
}

.input-tab {
  padding: 0.9rem 1.4rem;
  font-size: 0.87rem;
  font-weight: 700;
  color: var(--text-2);
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: -1px;
}

.input-tab:hover { color: var(--text-1); }

.input-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* JSON Textarea */
.paste-area-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.json-textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  background: var(--bg-2);
  border: 1.5px solid var(--border-2);
  border-radius: var(--r-lg);
  color: var(--text-1);
  font-family: 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  padding: 1rem 1.1rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
  display: block;
}

.json-textarea::placeholder {
  color: var(--text-3);
  font-family: 'Inter', sans-serif;
}

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

.json-textarea.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.12);
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

.paste-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.65rem;
  padding-bottom: 1.25rem;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 820px) {
  .score-main-card {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .score-dial-wrap { margin: 0 auto; }
  .score-grid { grid-template-columns: repeat(2, 1fr); }

  .exam-sidebar { display: none; }
  .exam-title-text { display: none; }
}

@media (max-width: 520px) {
  .home-main { padding: 2rem 1rem; }
  .score-grid { grid-template-columns: repeat(2, 1fr); }
  .exam-bottom { gap: 0.35rem; padding: 0 0.75rem; }
  .btn { padding: 0.5rem 0.85rem; font-size: 0.78rem; }
  .btn-sm { padding: 0.35rem 0.65rem; font-size: 0.72rem; }
}
