* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  padding: 1rem;
  background: #f5f5f7;
  color: #1a1a1a;
}

.login-card {
  max-width: 360px;
  margin: 3rem auto;
  padding: 1.5rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.login-card h1 {
  font-size: 1.25rem;
  margin-top: 0;
}

form label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

form input {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  margin-top: 1.25rem;
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

.error {
  color: #b91c1c;
  margin-top: 1rem;
}

.field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: #6b7280;
}

.field-hint.ok {
  color: #15803d;
}

form input:read-only {
  background: #f3f4f6;
  color: #374151;
}

.exam-header {
  max-width: 640px;
  margin: 0 auto 1rem;
}

.exam-meta {
  font-size: 0.9rem;
  color: #4b5563;
  margin-top: 0.25rem;
  line-height: 1.5;
}

.exam-timer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  margin: 0;
  padding: 0.6rem 1rem;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a1a;
  background: #f5f5f7;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.exam-timer.low-time {
  color: #b91c1c;
}

.exam-main {
  padding-top: 3rem;
}

#questions-container {
  max-width: 640px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
}

/* One question on screen at a time (CLAUDE.md: Next/Previous/navigator) —
   every card exists in the DOM from renderQuestions(), only the one with
   .active (set by exam.js's showQuestion()) is actually shown. */
.question-card {
  display: none;
  background: white;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.question-card.active {
  display: block;
}

.question-card h3 {
  margin-top: 0;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
}

.option-row label {
  flex: 1;
}

.short-answer-input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  resize: vertical;
}

.ordering-instructions {
  font-size: 0.85rem;
  color: #4b5563;
  margin: 0 0 0.5rem;
}

.ordering-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.ordering-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #f5f5f7;
  font-size: 0.95rem;
}

.ordering-text {
  /* basis 200px + the select's own min-width is what triggers the wrap
     below on a narrow phone — a short stem still fits both on one line. */
  flex: 1 1 200px;
  word-break: break-word;
}

.ordering-position-select {
  /* A plain 1-2 digit number is all the option text ever is, so this can
     stay small; margin-left: auto keeps it pinned to the row's end even
     after wrapping onto its own line under a long stem. */
  flex: 0 0 auto;
  margin-left: auto;
  width: auto;
  min-width: 3.4rem;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
}

.ordering-reset-btn {
  width: auto;
  background: none;
  border: 1px solid #ccc;
  color: #4b5563;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.save-indicator {
  font-size: 0.8rem;
  color: #16a34a;
  margin-top: 0.4rem;
  min-height: 1em;
}

#submit-area {
  max-width: 640px;
  margin: 0 auto 2rem;
}

#result-panel {
  max-width: 640px;
  margin: 1rem auto;
  padding: 1rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* [hidden] and .overlay both have single-selector specificity, and author
   CSS loads after the UA stylesheet, so .overlay { display: flex } would
   otherwise win and show the overlay even while hidden. This raises the
   hidden-state specificity so it always wins instead. */
.overlay[hidden] {
  display: none;
}

.overlay-start {
  background: rgba(67, 56, 202, 0.96);
}

.overlay-warning {
  background: rgba(180, 83, 9, 0.96);
}

.overlay-lockout {
  background: rgba(153, 27, 27, 0.97);
}

.overlay-submitted {
  background: rgba(21, 94, 117, 0.97);
}

.overlay-pause {
  background: rgba(30, 41, 59, 0.97);
}

.overlay-box {
  max-width: 420px;
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
}

.overlay-box h2 {
  margin-top: 0;
}

.overlay-box button {
  margin-top: 1rem;
}

#override-form {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e5e5;
}

.override-hint {
  font-size: 0.85rem;
  color: #4b5563;
}

#override-code-input {
  width: 100%;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-align: center;
}

#override-form button {
  margin-top: 0.6rem;
}

#override-countdown {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e5e5;
}

/* ---- Matching questions ---- */

.matching-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0f0f0;
}

.matching-row:last-child {
  border-bottom: none;
}

.matching-left {
  flex: 1;
  font-size: 0.95rem;
}

.matching-row select {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
}

.matching-lock {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 1.1rem;
  cursor: pointer;
  user-select: none;
}

.matching-lock input {
  cursor: pointer;
}

.matching-lock input:disabled {
  cursor: not-allowed;
}

.matching-row.matching-locked {
  background: #eefbf0;
  border-radius: 4px;
}

.matching-row.matching-locked select {
  border-color: #2e8b57;
  color: #2e8b57;
  font-weight: 600;
  background: #f4fff6;
}

/* ---- Image labeling: shared by the student exam page and the teacher's
   standalone label-picker page (label_picker.html/js). ---- */

.image-label-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin-top: 0.5rem;
  user-select: none;
}

.image-label-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: crosshair;
}

.image-label-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.85);
  border: 2px solid white;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.label-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.label-chip {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid #ccc;
  background: #f5f5f7;
  font-size: 0.85rem;
  cursor: pointer;
}

.label-chip.placed {
  background: #dcfce7;
  border-color: #16a34a;
  color: #166534;
}

.label-chip.armed {
  background: #dbeafe;
  border-color: #2563eb;
  color: #1e3a8a;
  font-weight: 600;
}

/* ---- Phase 2b: per-question timer, review flagging, navigator ---- */

.question-nav-bar {
  max-width: 640px;
  margin: 0 auto 1rem;
}

.question-timer-line {
  font-size: 0.85rem;
  font-weight: 600;
  color: #4b5563;
  text-align: center;
  margin-bottom: 0.5rem;
}

/* Per-question countdown color stages: green for most of the budget, amber
   for the last ~20%, red once over budget (counting up as overtime). */
.question-timer-line.time-green {
  color: #15803d;
}

.question-timer-line.time-amber {
  color: #b45309;
}

.question-timer-line.time-red {
  color: #b91c1c;
}

.question-nav-buttons {
  display: flex;
  gap: 0.75rem;
}

.question-nav-buttons button {
  flex: 1;
  margin: 0;
  width: auto;
}

.question-nav-buttons button:disabled {
  background: #d1d5db;
  cursor: not-allowed;
}

.review-toggle-btn {
  width: auto;
  margin: 0.75rem 0 0;
  padding: 0.4rem 0.8rem;
  background: #f5f5f7;
  color: #4b5563;
  border: 1px solid #ccc;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.review-toggle-btn:hover {
  background: #e5e5e5;
}

.review-toggle-btn.active {
  background: #fef3c7;
  border-color: #d97706;
  color: #92400e;
}

.time-budget-banner {
  max-width: 640px;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  background: #fef3c7;
  border: 1px solid #d97706;
  border-radius: 8px;
  color: #92400e;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Same reasoning as .overlay[hidden] above: this rule declares `display`,
   so it needs the extra specificity to still win while [hidden]. */
.time-budget-banner[hidden] {
  display: none;
}

#time-budget-banner-dismiss {
  width: auto;
  margin: 0;
  padding: 0.1rem 0.5rem;
  background: transparent;
  color: #92400e;
  font-size: 1.2rem;
  line-height: 1;
  border: none;
  cursor: pointer;
}

#time-budget-banner-dismiss:hover {
  background: rgba(217, 119, 6, 0.15);
  border-radius: 4px;
}

.nav-toggle-btn {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 400;
  width: auto;
  margin: 0;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: #2563eb;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.nav-toggle-btn:hover {
  background: #1d4ed8;
}

.nav-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
}

.nav-panel-overlay[hidden] {
  display: none;
}

.nav-panel {
  width: 100%;
  max-width: 640px;
  max-height: 70vh;
  overflow-y: auto;
  background: white;
  border-radius: 12px 12px 0 0;
  padding: 1rem 1rem 1.5rem;
}

.nav-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

#nav-panel-close-btn {
  width: auto;
  margin: 0;
  padding: 0.2rem 0.6rem;
  background: #f5f5f7;
  color: #1a1a1a;
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
}

#nav-panel-close-btn:hover {
  background: #e5e5e5;
}

.nav-panel-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: #4b5563;
}

.nav-legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
}

.nav-swatch-answered {
  background: #dcfce7;
  border: 1px solid #16a34a;
}

.nav-swatch-unanswered {
  background: #f5f5f7;
  border: 1px solid #ccc;
}

.nav-swatch-review {
  background: #fef3c7;
  border: 1px solid #d97706;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.nav-grid-btn {
  aspect-ratio: 1;
  width: auto;
  margin: 0;
  padding: 0;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #f5f5f7;
  color: #1a1a1a;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-grid-btn.nav-answered {
  background: #dcfce7;
  border-color: #16a34a;
  color: #166534;
}

.nav-grid-btn.nav-review {
  background: #fef3c7;
  border-color: #d97706;
  color: #92400e;
}

.nav-grid-btn.nav-active {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}