* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: #ffffff;
  color: #1a1a1a;
  line-height: 1.5;
}
#app { max-width: 900px; margin: 0 auto; padding: 24px; }

/* Test-taking screen needs more horizontal space than the homepage.
   renderTest() sets body.in-test so the container can widen and the PDF
   column becomes readable. renderStart() / restart() clears it. */
body.in-test #app { max-width: 1500px; }

.topbar {
  position: sticky; top: 0; background: #fff;
  border-bottom: 1px solid #e3e3e3;
  padding: 12px 0; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: center;
  z-index: 10;
}
.section-title { font-size: 16px; font-weight: 600; color: #333; }
.timer {
  font-family: "Menlo", monospace; font-size: 22px; font-weight: 700;
  padding: 6px 14px; border-radius: 6px; background: #f4f4f4;
}
.timer.warn { background: #fff3cd; color: #8a6d00; }
.timer.danger { background: #f8d7da; color: #a42834; }

.start-card { text-align: center; padding: 40px 20px; }
.start-card h1 { font-size: 32px; margin-bottom: 8px; }
.start-card p { color: #555; }
.mode-buttons {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  margin: 24px 0;
}
.mode-card {
  border: 1px solid #ddd; border-radius: 8px; padding: 20px; background: #fafafa;
  min-width: 260px; max-width: 280px; text-align: left; cursor: pointer;
  transition: all 0.15s;
}
.mode-card:hover { border-color: #0066cc; background: #f0f7ff; transform: translateY(-2px); }
.mode-card h3 { margin: 0 0 8px; font-size: 17px; color: #0066cc; }
.mode-card .badge {
  display: inline-block; padding: 2px 8px; background: #0066cc; color: white;
  border-radius: 10px; font-size: 11px; font-weight: 600; margin-left: 6px;
}
.mode-card .badge.hard { background: #c9302c; }
.mode-card .badge.official { background: #28a745; }
.mode-card p { font-size: 13px; color: #555; margin: 6px 0 0; }

.sections-list {
  display: flex; gap: 16px; justify-content: center;
  margin: 30px 0; flex-wrap: wrap;
}
.section-box {
  border: 1px solid #ddd; border-radius: 8px;
  padding: 18px 22px; min-width: 180px; background: #fafafa;
}
.section-box h3 { margin: 0 0 6px; font-size: 16px; }
.section-box .mins { color: #0066cc; font-weight: 600; }

.question-card {
  border: 1px solid #e3e3e3; border-radius: 8px;
  padding: 24px; background: #fff;
}
.qnum { color: #666; font-size: 14px; margin-bottom: 8px; }
.qtext { font-size: 17px; margin-bottom: 18px; white-space: pre-wrap; }
.qpassage {
  background: #f8f9fa; border-left: 3px solid #0066cc;
  padding: 14px 16px; margin-bottom: 16px; border-radius: 4px;
  font-size: 15px; white-space: pre-wrap;
}
.qbox {
  background: #fffbea; border: 1px solid #f0d878;
  padding: 10px 14px; margin-bottom: 14px; border-radius: 4px;
  font-style: italic; font-size: 14px;
}
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  border: 1px solid #d0d0d0; border-radius: 6px;
  padding: 12px 16px; cursor: pointer; background: #fff;
  transition: all 0.15s; display: flex; align-items: center; gap: 12px;
}
.option:hover { border-color: #0066cc; background: #f0f7ff; }
.option.selected { border-color: #0066cc; background: #e6f0fc; }
.option-letter {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid #999; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.option.selected .option-letter {
  background: #0066cc; color: #fff; border-color: #0066cc;
}

.nav-buttons {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 20px;
}
button {
  font-family: inherit; font-size: 15px;
  padding: 10px 20px; border-radius: 6px; cursor: pointer;
  border: 1px solid #0066cc; background: #0066cc; color: #fff;
  font-weight: 600;
}
button:hover { background: #0052a3; }
button.secondary { background: #fff; color: #0066cc; }
button.secondary:hover { background: #f0f7ff; }
button.danger { background: #d9534f; border-color: #d9534f; }
button.danger:hover { background: #c9302c; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.flag-btn {
  background: #fff; color: #666; border-color: #ccc;
  font-size: 13px; padding: 6px 12px;
}
.flag-btn.flagged { background: #fff3cd; color: #8a6d00; border-color: #e0c26a; }

.qgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px; margin-top: 16px; padding: 16px;
  background: #fafafa; border-radius: 8px;
}
.qgrid button {
  padding: 8px; font-size: 13px; min-width: 0;
  background: #fff; color: #333; border: 1px solid #ccc;
}
.qgrid button.answered { background: #d4edda; border-color: #8bc498; color: #155724; }
.qgrid button.flagged { background: #fff3cd; border-color: #e0c26a; }
.qgrid button.current { outline: 3px solid #0066cc; outline-offset: 1px; }

.results h1 { font-size: 28px; margin-bottom: 6px; }
.score-big {
  font-size: 64px; font-weight: 700; color: #0066cc;
  margin: 20px 0 8px;
}
.score-pct { font-size: 22px; color: #555; margin-bottom: 30px; }
.section-result {
  display: flex; justify-content: space-between;
  padding: 12px 16px; border: 1px solid #e3e3e3;
  border-radius: 6px; margin-bottom: 8px;
}
.review-item {
  border-top: 1px solid #eee; padding: 18px 0;
}
.review-item.wrong .verdict { color: #c9302c; }
.review-item.right .verdict { color: #28a745; }
.verdict { font-weight: 700; font-size: 13px; text-transform: uppercase; }
.explanation {
  background: #f8f9fa; border-left: 3px solid #0066cc;
  padding: 12px 14px; margin-top: 10px; border-radius: 4px;
  font-size: 14px;
}
.your-answer, .correct-answer { font-size: 14px; margin-top: 6px; }
.your-answer span, .correct-answer span { font-weight: 600; }

.history-table {
  width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px;
}
.history-table th, .history-table td {
  border: 1px solid #e3e3e3; padding: 8px 10px; text-align: left;
}
.history-table th { background: #fafafa; font-weight: 600; }
.pdf-viewer {
  width: 100%; height: 80vh;
  border: 1px solid #ddd; border-radius: 4px;
  overflow-y: auto; overflow-x: auto;
  background: #525659; /* PDF-viewer grey backdrop behind pages */
  padding: 8px;
}
.loading {
  text-align: center; padding: 40px; color: #666;
}
.loading::after {
  content: ""; display: inline-block; width: 20px; height: 20px;
  border: 3px solid #0066cc; border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite; margin-left: 10px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none; }
