:root {
  --navy: #0d2b4e;
  --navy-dark: #071a33;
  --blue: #1a5fb4;
  --blue-light: #e8f1fb;
  --green: #1f8a4c;
  --green-light: #e6f6ec;
  --red: #c53030;
  --red-light: #fdecec;
  --amber: #b7791f;
  --amber-light: #fef3d9;
  --gray-50: #f7f8fa;
  --gray-100: #eef0f3;
  --gray-200: #dfe3e8;
  --gray-400: #98a2b3;
  --gray-600: #667085;
  --gray-800: #344054;
  --text: #1a2233;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--gray-50);
  line-height: 1.5;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
.container-narrow { max-width: 640px; margin: 0 auto; padding: 0 20px; }

/* ---- Top nav ---- */
.topnav {
  background: var(--navy);
  color: white;
  padding: 14px 0;
}
.topnav .container { display: flex; align-items: center; justify-content: space-between; }
.topnav .brand { font-weight: 700; font-size: 18px; color: white; letter-spacing: 0.2px; }
.topnav .brand span { color: #7fb2ff; }
.topnav nav a { color: #cfe0f5; margin-left: 20px; font-size: 14px; }
.topnav nav a:hover { color: white; text-decoration: none; }
.topnav button.linklike {
  background: none; border: none; color: #cfe0f5; font-size: 14px; cursor: pointer; margin-left: 20px; font-family: inherit;
}
.topnav button.linklike:hover { color: white; }

/* ---- Cards / layout ---- */
.page { padding: 40px 0 80px; }
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

h1 { font-size: 28px; margin: 0 0 8px; }
h2 { font-size: 20px; }
.subtitle { color: var(--gray-600); margin-bottom: 28px; }

/* ---- Forms ---- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-800); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 16px;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

.btn {
  display: inline-block;
  background: var(--blue);
  color: white;
  border: none;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #164a8f; text-decoration: none; }
.btn:disabled { background: var(--gray-400); cursor: not-allowed; }
.btn-secondary { background: white; color: var(--blue); border: 1px solid var(--blue); }
.btn-secondary:hover { background: var(--blue-light); }
.btn-danger { background: white; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red-light); }
.btn-block { width: 100%; text-align: center; }
.btn-sm { padding: 6px 14px; font-size: 13px; }

.error-msg {
  background: var(--red-light); color: var(--red); border: 1px solid #f5c2c2;
  padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; display: none;
}
.error-msg.show { display: block; }

/* ---- Exam list ---- */
.exam-card { display: flex; justify-content: space-between; align-items: center; }
.exam-card .meta { color: var(--gray-600); font-size: 14px; margin-top: 4px; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge-pass { background: var(--green-light); color: var(--green); }
.badge-fail { background: var(--red-light); color: var(--red); }
.badge-progress { background: var(--amber-light); color: var(--amber); }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }

table.history { width: 100%; border-collapse: collapse; font-size: 14px; }
table.history th, table.history td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--gray-100); }
table.history th { color: var(--gray-600); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---- Exam-taking screen ---- */
.exam-shell { display: flex; flex-direction: column; min-height: 100vh; }
.exam-header {
  background: var(--navy-dark); color: white; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.exam-header .block-label { font-weight: 600; }
.exam-header .timer { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 700; padding: 4px 14px; border-radius: 8px; background: rgba(255,255,255,0.08); }
.exam-header .timer.low { background: var(--red); }
.exam-header .actions button { margin-left: 10px; }

.exam-body { flex: 1; display: flex; }
.question-nav {
  width: 220px; background: white; border-right: 1px solid var(--gray-200); padding: 16px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; align-content: start;
}
.qnav-btn {
  border: 1px solid var(--gray-200); background: white; border-radius: 6px; padding: 8px 0; font-size: 13px;
  cursor: pointer; position: relative; font-family: inherit;
}
.qnav-btn.current { border-color: var(--blue); border-width: 2px; }
.qnav-btn.answered { background: var(--blue-light); border-color: var(--blue); }
.qnav-btn.flagged::after {
  content: "\2691"; position: absolute; top: -6px; right: -4px; color: var(--amber); font-size: 12px;
}

.question-main { flex: 1; padding: 32px 40px; max-width: 800px; }
.question-stem { font-size: 16px; margin-bottom: 24px; white-space: pre-wrap; }
.choice {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border: 1px solid var(--gray-200);
  border-radius: 8px; margin-bottom: 10px; cursor: pointer; background: white;
}
.choice:hover { border-color: var(--blue); }
.choice.selected { border-color: var(--blue); background: var(--blue-light); }
.choice input { margin-top: 3px; }
.choice .letter { font-weight: 700; color: var(--gray-600); width: 18px; }

.question-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 28px; }
.flag-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--amber); font-weight: 600; font-size: 14px; user-select: none; }

/* ---- Results ---- */
.score-hero { text-align: center; padding: 20px 0 8px; }
.score-hero .score { font-size: 56px; font-weight: 800; color: var(--navy); }
.score-hero .scale { color: var(--gray-600); font-size: 14px; }
.pass-pill { display: inline-block; margin-top: 12px; padding: 6px 18px; border-radius: 999px; font-weight: 700; }
.disclaimer {
  font-size: 12px; color: var(--gray-600); background: var(--gray-100); border-radius: 8px; padding: 10px 14px; margin: 16px 0;
}

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; }
.bar-row .label { width: 220px; flex-shrink: 0; color: var(--gray-800); }
.bar-track { flex: 1; background: var(--gray-100); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--blue); }
.bar-row .pct { width: 50px; text-align: right; color: var(--gray-600); }

/* ---- Review ---- */
.review-filters { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-chip {
  border: 1px solid var(--gray-200); background: white; border-radius: 999px; padding: 6px 16px; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.filter-chip.active { background: var(--navy); color: white; border-color: var(--navy); }

.review-item { border-bottom: 1px solid var(--gray-100); padding: 24px 0; }
.review-item:first-child { padding-top: 0; }
.review-item .tag-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.review-item .qnum { color: var(--gray-600); font-size: 13px; }
.review-choice { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; border: 1px solid var(--gray-200); }
.review-choice.correct-choice { border-color: var(--green); background: var(--green-light); }
.review-choice.your-wrong-choice { border-color: var(--red); background: var(--red-light); }
.review-choice .choice-label { font-weight: 700; margin-right: 6px; }
.review-choice .tagword { font-size: 12px; font-weight: 700; margin-left: 8px; }
.review-choice .tagword.correct { color: var(--green); }
.review-choice .tagword.yours { color: var(--red); }
.review-explanation { font-size: 14px; color: var(--gray-800); margin-top: 4px; padding-left: 4px; }

/* ---- Quiz builder ---- */
.category-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 20px; }
.category-checks label { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; color: var(--text); margin-bottom: 0; }
.category-checks input { width: auto; margin: 0; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(13,43,78,0.55); display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box { background: white; border-radius: var(--radius); padding: 32px; max-width: 420px; text-align: center; }

@media (max-width: 800px) {
  .exam-body { flex-direction: column; }
  .question-nav { width: 100%; grid-template-columns: repeat(8, 1fr); border-right: none; border-bottom: 1px solid var(--gray-200); }
  .question-main { padding: 24px 20px; }
}
