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

:root {
  --primary: #1e3a5f;
  --accent: #f59e0b;
  --green: #16a34a;
  --red: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* --- HEADER --- */
header {
  background: var(--primary);
  color: #fff;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
header .logo { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.5px; }
header .logo span { color: var(--accent); }
header .user-info { font-size: 0.85rem; color: #94a3b8; }
header .btn-logout {
  background: transparent;
  border: 1px solid #475569;
  color: #94a3b8;
  padding: 0.35rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
header .btn-logout:hover { background: #334155; color: #fff; }

/* --- AUTH PAGES --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-card h1 { font-size: 1.8rem; font-weight: 800; color: var(--primary); margin-bottom: 0.3rem; }
.auth-card h1 span { color: var(--accent); }
.auth-card .subtitle { color: var(--muted); font-size: 0.9rem; margin-bottom: 2rem; }

.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); }

.captcha-box {
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.2rem;
}
.captcha-box .captcha-q { font-size: 1.1rem; font-weight: 700; color: var(--primary); flex: 1; }
.captcha-box input {
  width: 80px;
  padding: 0.5rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  text-align: center;
  outline: none;
}
.captcha-box input:focus { border-color: var(--primary); }

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.85rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: #163050; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}

/* --- DASHBOARD --- */
.container { max-width: 900px; margin: 0 auto; padding: 2rem; }

.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  text-align: center;
}
.stat-card .val { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-card .lbl { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; margin-top: 0.3rem; }

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.section-card h2 { font-size: 1.3rem; font-weight: 700; color: var(--primary); margin-bottom: 0.5rem; }
.section-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }

.btn-start {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 0.7rem 2rem;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: none;
  font-size: 0.95rem;
  transition: background 0.2s;
}
.btn-start:hover { background: #163050; }

/* --- QUIZ PAGE --- */
.quiz-wrap { max-width: 760px; margin: 0 auto; padding: 2rem; }

.progress-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 8px;
  margin-bottom: 2rem;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #3b82f6);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.question-counter {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.6rem;
}

.question-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}

.question-text {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.btn-reveal {
  background: var(--accent);
  color: #1c1917;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-reveal:hover { background: #d97706; }
.btn-reveal:active { transform: scale(0.98); }

.answer-box {
  display: none;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.2rem;
}
.answer-box.show { display: block; }
.answer-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--green);
  letter-spacing: 0.8px;
  margin-bottom: 0.5rem;
}
.answer-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #166534;
}
.answer-text p, .qa-answer p, .formatted-answer p {
  margin: 0 0 0.6rem;
}
.answer-text p:last-child, .qa-answer p:last-child, .formatted-answer p:last-child {
  margin-bottom: 0;
}
.answer-text ul, .qa-answer ul, .formatted-answer ul {
  margin: 0.3rem 0 0.6rem 1.2rem;
  padding: 0;
}
.answer-text li, .qa-answer li, .formatted-answer li {
  margin-bottom: 0.25rem;
  line-height: 1.55;
}
.answer-text .answer-subheading, .qa-answer .answer-subheading, .formatted-answer .answer-subheading {
  margin: 0.7rem 0 0.2rem;
  font-size: 0.9rem;
  color: var(--text);
}
.answer-text .answer-subheading:first-child, .qa-answer .answer-subheading:first-child { margin-top: 0; }
.answer-text .answer-note, .qa-answer .answer-note, .formatted-answer .answer-note {
  background: #fefce8;
  border-left: 3px solid #eab308;
  padding: 0.4rem 0.7rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.88rem;
  color: #713f12;
  margin: 0.5rem 0;
}

.nav-buttons {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.btn-nav {
  padding: 0.7rem 1.8rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 2px solid var(--primary);
  transition: all 0.2s;
}
.btn-nav.prev { background: transparent; color: var(--primary); }
.btn-nav.prev:hover { background: var(--primary); color: #fff; }
.btn-nav.next { background: var(--primary); color: #fff; }
.btn-nav.next:hover { background: #163050; }
.btn-nav.finish-early { background: #fff; color: #dc2626; border-color: #dc2626; }
.btn-nav.finish-early:hover { background: #fef2f2; }
.btn-nav:disabled { opacity: 0.4; cursor: not-allowed; }

.self-grade {
  display: none;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.self-grade.show { display: flex; }
.grade-btn {
  flex: 1;
  min-width: 100px;
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.grade-btn.correct { background: #f0fdf4; border-color: #16a34a; color: #16a34a; }
.grade-btn.correct:hover, .grade-btn.correct.selected { background: #16a34a; color: #fff; }
.grade-btn.partial { background: #fffbeb; border-color: #d97706; color: #d97706; }
.grade-btn.partial:hover, .grade-btn.partial.selected { background: #d97706; color: #fff; }
.grade-btn.wrong { background: #fef2f2; border-color: #dc2626; color: #dc2626; }
.grade-btn.wrong:hover, .grade-btn.wrong.selected { background: #dc2626; color: #fff; }

/* Session summary */
.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  text-align: center;
  max-width: 520px;
  margin: 3rem auto;
}
.summary-card h2 { font-size: 1.8rem; font-weight: 800; color: var(--primary); margin-bottom: 0.5rem; }
.summary-score { font-size: 3rem; font-weight: 900; color: var(--accent); margin: 1rem 0; }
.summary-card p { color: var(--muted); margin-bottom: 2rem; }

/* --- MCQ OPTIONS --- */
.options-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
  transition: all 0.15s;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #eff6ff;
}
.option-btn.correct {
  background: #f0fdf4;
  border-color: #16a34a;
  color: #15803d;
}
.option-btn.wrong {
  background: #fef2f2;
  border-color: #dc2626;
  color: #b91c1c;
}
.option-btn:disabled { cursor: default; }

.opt-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.option-btn.correct .opt-letter { background: #16a34a; }
.option-btn.wrong .opt-letter { background: #dc2626; }

.opt-text { flex: 1; }

/* Explanation */
.explanation-box {
  margin-top: 1.25rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 1rem 1.25rem;
}
.exp-result {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.result-correct { color: #16a34a; }
.result-wrong { color: #dc2626; }
.exp-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #92400e;
  margin-bottom: 0.4rem;
}
.exp-text {
  font-size: 0.88rem;
  line-height: 1.65;
  color: #78350f;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

/* Watermark */
.watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-size: 4rem;
  font-weight: 900;
  color: rgba(30, 58, 95, 0.04);
  pointer-events: none;
  white-space: nowrap;
  z-index: 0;
  user-select: none;
}

/* Overlay for devtools detection */
.devtools-warning {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
}
.devtools-warning h2 { font-size: 1.5rem; margin-bottom: 1rem; }
.devtools-warning p { color: #94a3b8; }

/* Responsive */
@media (max-width: 600px) {
  .container, .quiz-wrap { padding: 1rem; }
  .question-card { padding: 1.25rem; }
  .auth-card { padding: 1.5rem; }
  header { padding: 0.75rem 1rem; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
}
