/* quiz.css — quiz-specific layout, form controls, markdown content,
   review grid, results page, mobile breakpoint at 640px. */

/* ────────────────────────────────────────────── header / progress */

.quiz-header {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--border-soft);
}

.quiz-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
  justify-content: space-between;
  color: var(--text-dim);
  font-size: var(--fs-sm);
}

.quiz-meta .counter strong { color: var(--text); }

.quiz-meta .bank-num {
  color: var(--text-mute);
}

.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--green) 0%, var(--accent) 100%);
  transition: width .25s ease;
}

.mark-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mark-toggle:hover { color: var(--text); border-color: var(--text-dim); }
.mark-toggle[aria-pressed="true"] {
  color: var(--yellow);
  border-color: var(--yellow);
}

/* Discoverable trigger for the keyboard shortcuts modal */
.kbd-hint {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mute);
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  min-height: 28px;
  align-self: flex-start;
}
.kbd-hint:hover { color: var(--text-dim); border-color: var(--text-dim); }
@media (max-width: 640px) { .kbd-hint { display: none; } }

/* ────────────────────────────────────────────── question card */

.question-card { margin-bottom: var(--s-6); }

.question-title {
  color: var(--accent-2);
  font-size: var(--fs-lg);
  font-weight: 700;
  margin-bottom: var(--s-4);
  line-height: 1.4;
}

.scenario {
  margin-bottom: var(--s-5);
  padding: var(--s-4);
  background: var(--bg-elevated);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-xs);
}

.helper-text {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-3);
  font-style: italic;
}

/* ────────────────────────────────────────────── option cards (radio/checkbox) */

.options { list-style: none; display: flex; flex-direction: column; gap: var(--s-2); }

.option {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  min-height: 44px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.option:hover { border-color: var(--text-mute); background: var(--bg-soft); }
.option:focus-within {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.option input[type="radio"],
.option input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border: 1.5px solid var(--text-mute);
  background: var(--bg);
  flex: 0 0 auto;
  margin-top: 2px;
  cursor: pointer;
  position: relative;
}
.option input[type="radio"] { border-radius: 50%; }
.option input[type="checkbox"] { border-radius: 3px; }
.option input[type="radio"]:checked,
.option input[type="checkbox"]:checked {
  border-color: var(--green);
  background: var(--green);
}
.option input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  background: var(--bg);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.option input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -55%);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}
.option input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.option .letter {
  color: var(--accent-2);
  font-weight: 700;
  flex: 0 0 auto;
}
.option .opt-text { flex: 1; }

.option.selected { border-color: var(--green); background: var(--bg-soft); }

/* ────────────────────────────────────────────── ordered (numbered selects + drag) */

.ordered-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.ordered-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  min-height: 44px;
}
.ordered-row .pos {
  color: var(--text-mute);
  font-weight: 700;
  min-width: 24px;
}
.ordered-row select { flex: 0 0 auto; }
.ordered-row .pos-label { flex: 1; color: var(--text-dim); font-size: var(--fs-sm); }

/* Drag-to-reorder UI (progressively enhanced; .drag-active set by JS) */
.drag-list {
  list-style: none;
  display: none;
  flex-direction: column;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.drag-list.active { display: flex; }
.ordered-list.hidden-by-drag { display: none; }

.drag-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  min-height: 44px;
  cursor: grab;
  user-select: none;
}
.drag-item.dragging { opacity: .4; cursor: grabbing; }
.drag-item.drop-target { border-color: var(--accent); }
.drag-item .handle { color: var(--text-mute); }
.drag-item .pos    { color: var(--accent-2); font-weight: 700; min-width: 24px; }
.drag-item .letter { color: var(--accent-2); font-weight: 700; }
.drag-item .opt-text { flex: 1; }

/* ────────────────────────────────────────────── table-kind questions */

.table-rows {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.table-row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  min-height: 44px;
  flex-wrap: wrap;
}
.table-row .item {
  flex: 1;
  min-width: 200px;
  color: var(--text);
}
.table-row .controls {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  flex-wrap: wrap;
}
.table-row .yn-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  cursor: pointer;
  min-height: 32px;
}

/* ────────────────────────────────────────────── form controls */

select, input[type="number"], input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  font-family: inherit;
  font-size: var(--fs-base);
  min-height: 40px;
}
select:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

label { color: var(--text-dim); }

/* ────────────────────────────────────────────── action bar (Prev / Skip / Next ...) */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border-soft);
}
.actions .spacer { flex: 1; }

/* ────────────────────────────────────────────── setup form */

.setup-form { display: flex; flex-direction: column; gap: var(--s-5); }
.setup-form .field { display: flex; flex-direction: column; gap: 6px; }
.setup-form .field label { font-weight: 700; color: var(--text-dim); }
.setup-form .field .hint { color: var(--text-mute); font-size: var(--fs-sm); }
.setup-form .checkbox-row {
  display: flex; align-items: center; gap: var(--s-2);
}
.setup-form .checkbox-row label { font-weight: 400; color: var(--text); }

.resume-banner {
  background: var(--bg-elevated);
  border: 1px solid var(--yellow);
  border-left: 4px solid var(--yellow);
  padding: var(--s-4);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s-5);
}
.resume-banner .resume-actions {
  display: flex; gap: var(--s-2); margin-top: var(--s-3); flex-wrap: wrap;
}

/* ────────────────────────────────────────────── markdown content (per contract §5) */

.md-content { color: var(--text); }
.md-content p { margin: 0 0 var(--s-3); }
.md-content p:last-child { margin-bottom: 0; }

.md-content code {
  background: #0a0e13;
  border: 1px solid var(--border-soft);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: .9em;
  color: #e6edf3;
}
.md-content pre {
  background: #010409;
  border: 1px solid var(--border);
  padding: var(--s-3);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: var(--s-3) 0;
  font-size: 13px;
  line-height: 1.5;
}
.md-content pre code {
  background: transparent;
  border: 0;
  padding: 0;
}
.md-content ul,
.md-content ol {
  margin: var(--s-3) 0 var(--s-3) var(--s-5);
}
.md-content li { margin-bottom: 4px; }
.md-content table {
  border-collapse: collapse;
  margin: var(--s-3) 0;
  width: 100%;
  font-size: 13px;
}
.md-content th,
.md-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.md-content th { background: var(--bg-soft); color: var(--accent-2); }
.md-content blockquote {
  border-left: 3px solid var(--text-mute);
  padding-left: var(--s-3);
  color: var(--text-dim);
  margin: var(--s-3) 0;
}
.md-content a { color: var(--accent); }

/* ────────────────────────────────────────────── review grid */

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: var(--s-2);
  margin: var(--s-5) 0;
}
.review-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--s-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  min-height: 60px;
  text-decoration: none;
  color: var(--text);
  font-size: var(--fs-sm);
}
.review-cell:hover { border-color: var(--accent); text-decoration: none; }
.review-cell .pos { font-weight: 700; }
.review-cell .icon { font-size: 16px; line-height: 1; }
.review-cell .bank { color: var(--text-mute); font-size: 11px; }
.review-cell.answered    { border-color: var(--green); }
.review-cell.answered .icon { color: var(--green); }
.review-cell.skipped  .icon { color: var(--text-mute); }
.review-cell.marked      { border-color: var(--yellow); }
.review-cell.marked .icon   { color: var(--yellow); }
.review-cell.unanswered .icon { color: var(--text-mute); }

.review-summary {
  display: flex;
  gap: var(--s-4);
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-3);
}
.review-summary .legend {
  display: inline-flex; align-items: center; gap: 4px;
}

/* ────────────────────────────────────────────── results */

.score-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-4);
  padding: var(--s-5);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--s-5);
}
.score-card .big {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-2);
}
.score-card .pct { color: var(--green); font-size: var(--fs-lg); font-weight: 700; }

/* Score band header — gradient tinted by performance */
.score-band {
  margin: 0 calc(-1 * var(--s-7)) var(--s-5);
  padding: var(--s-5) var(--s-7);
  border-bottom: 1px solid var(--border-soft);
}
.score-band h1 { margin: 0 0 4px; }
.score-band .tagline { color: var(--text-dim); font-size: var(--fs-sm); }
.score-band.score-good {
  background: linear-gradient(135deg, rgba(63,185,80,.18) 0%, rgba(63,185,80,.04) 60%, transparent 100%);
  border-bottom-color: rgba(63,185,80,.35);
}
.score-band.score-mid {
  background: linear-gradient(135deg, rgba(210,153,34,.18) 0%, rgba(210,153,34,.04) 60%, transparent 100%);
  border-bottom-color: rgba(210,153,34,.35);
}
.score-band.score-poor {
  background: linear-gradient(135deg, rgba(248,81,73,.18) 0%, rgba(248,81,73,.04) 60%, transparent 100%);
  border-bottom-color: rgba(248,81,73,.35);
}
.score-band.score-good h1 { color: var(--green); }
.score-band.score-mid h1  { color: var(--yellow); }
.score-band.score-poor h1 { color: var(--red); }
@media (max-width: 640px) {
  .score-band { margin: 0 calc(-1 * var(--s-4)) var(--s-4); padding: var(--s-4); }
}

.domain-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.domain-cell {
  padding: var(--s-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.domain-cell .name  { color: var(--text-dim); font-size: var(--fs-sm); }
.domain-cell .score { color: var(--text); font-weight: 700; font-size: var(--fs-md); }

.result-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}
.result-card {
  padding: var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--text-mute);
  border-radius: var(--radius-sm);
}
.result-card.correct   { border-left-color: var(--green); }
.result-card.incorrect { border-left-color: var(--red); }

.result-card .head {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.result-card .head .bank { color: var(--text-mute); font-size: var(--fs-sm); }
.result-card .head .title {
  color: var(--accent-2);
  font-weight: 700;
  flex: 1;
  min-width: 200px;
}
.result-card .head .verdict { font-weight: 700; }
.result-card.correct   .verdict { color: var(--green); }
.result-card.incorrect .verdict { color: var(--red); }

.answer-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  margin: var(--s-3) 0;
  font-size: var(--fs-sm);
}
.answer-row .label { color: var(--text-mute); }
.answer-row .your.correct  { color: var(--green); }
.answer-row .your.wrong    { color: var(--red); }
.answer-row .correct-ans   { color: var(--green); }

.rationale-block { margin-top: var(--s-3); }

/* ────────────────────────────────────────────── shortcuts modal */

.shortcuts-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
  z-index: 100;
}
.shortcuts-modal.open { display: flex; }
.shortcuts-modal .panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-5);
  max-width: 420px;
  width: 100%;
}
.shortcuts-modal h3 { color: var(--accent-2); margin-bottom: var(--s-3); }
.shortcuts-modal dl { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s-4); }
.shortcuts-modal dt {
  color: var(--accent);
  font-weight: 700;
}
.shortcuts-modal dd { color: var(--text-dim); }
.shortcuts-modal .close-row { display: flex; justify-content: flex-end; margin-top: var(--s-4); }

/* ────────────────────────────────────────────── mobile breakpoint */

@media (max-width: 640px) {
  :root { --window-max: 100%; }

  html, body { overflow-x: hidden; max-width: 100%; }

  .quiz-meta { font-size: 11px; gap: var(--s-2); }
  .question-title { font-size: var(--fs-md); }
  .scenario { padding: var(--s-3); }

  .option { padding: var(--s-3); gap: var(--s-2); }
  .option .letter { font-size: var(--fs-base); }
  .option .opt-text { word-break: break-word; overflow-wrap: anywhere; }

  .ordered-row { flex-wrap: wrap; }
  .ordered-row select { flex: 1 1 100%; min-height: 44px; }

  .table-row { flex-direction: column; align-items: flex-start; }
  .table-row .controls { width: 100%; }
  .table-row .controls select { width: 100%; }

  .actions { flex-direction: column; }
  .actions .btn { width: 100%; }
  .actions .spacer { display: none; }

  .review-grid {
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  }
  .review-cell { min-height: 56px; min-width: 44px; }

  .score-card { flex-direction: column; align-items: flex-start; }
  .score-card .big { font-size: 26px; }

  .setup-form .field input,
  .setup-form .field select { width: 100%; min-height: 44px; }

  .md-content pre { font-size: 12px; }
  .md-content { overflow-wrap: anywhere; }
}

/* ─────────── focus-visible polish for interactive cards ─────────── */
.review-cell:focus-visible,
.mark-toggle:focus-visible,
.drag-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

/* Active states on clickable cards */
.option:active { background: var(--bg-soft); }
.review-cell:active { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }

/* Empty state on setup */
.empty-state {
  padding: var(--s-6);
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  color: var(--text-dim);
}
.empty-state strong { color: var(--yellow); display: block; margin-bottom: var(--s-2); }
