/* cb-quiz-engine.css
 * Visual styling for the inline quiz engine.
 * Matches the existing .self-check aesthetic from polish.css for visual consistency.
 * Uses theme.css CSS variables (--accent, --bg2, --soft, --border2, etc).
 */

/* ============================================================
 * Shell — common to all question types
 * ============================================================ */
.qz {
  margin: 28px 0;
}

.qz-shell {
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--soft), var(--bg2));
  border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  transition: border-left-color .25s ease;
}

[data-theme="dark"] .qz-shell {
  border-color: #3a3a3f;
}

/* State-driven left border color cue */
.qz-shell[data-state="correct"]   { border-left-color: #22c55e; }
.qz-shell[data-state="incorrect"] { border-left-color: #ef4444; }
.qz-shell[data-state="revealed"]  { border-left-color: #f59e0b; }

.qz-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 10px;
}

.qz-stem {
  font-size: 15.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.55;
  margin-bottom: 16px;
}

.qz-stem strong { color: var(--text); }
.qz-stem em { color: var(--text2); font-style: italic; }
.qz-stem code {
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .9em;
}

/* ============================================================
 * MCQ
 * ============================================================ */
.qz-mcq .qz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.qz-opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}

[data-theme="dark"] .qz-opt {
  background: var(--bg3);
  border-color: #3a3a3f;
}

.qz-opt:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--soft);
  transform: translateX(2px);
}

.qz-opt:disabled {
  cursor: default;
  opacity: .85;
}

.qz-opt:disabled:not(.qz-opt-correct):not(.qz-opt-incorrect):not(.qz-opt-correct-other) {
  opacity: .55;
}

.qz-opt-letter {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg3);
  color: var(--text2);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.qz-opt-text {
  flex: 1;
}

/* Correct selection */
.qz-opt-correct {
  background: rgba(34, 197, 94, .12) !important;
  border-color: #22c55e !important;
  color: var(--text) !important;
}
.qz-opt-correct .qz-opt-letter {
  background: #22c55e;
  color: white;
}
.qz-opt-correct .qz-opt-letter::after {
  content: '';
}

/* Incorrect selection */
.qz-opt-incorrect {
  background: rgba(239, 68, 68, .12) !important;
  border-color: #ef4444 !important;
  color: var(--text) !important;
}
.qz-opt-incorrect .qz-opt-letter {
  background: #ef4444;
  color: white;
}

/* Show the correct answer when user picked wrong */
.qz-opt-correct-other {
  background: rgba(34, 197, 94, .06);
  border-color: rgba(34, 197, 94, .5);
  border-style: dashed;
}
.qz-opt-correct-other .qz-opt-letter {
  background: rgba(34, 197, 94, .35);
  color: white;
}

/* ============================================================
 * Short-answer
 * ============================================================ */
.qz-sa .qz-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.qz-input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.qz-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--ar), .15);
}

.qz-input:disabled {
  opacity: .85;
  cursor: default;
}

.qz-btn-check, .qz-btn-show, .qz-btn-reveal, .qz-btn-retry {
  padding: 11px 18px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease;
  white-space: nowrap;
}

.qz-btn-check:hover:not(:disabled),
.qz-btn-show:hover:not(:disabled),
.qz-btn-reveal:hover:not(:disabled),
.qz-btn-retry:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--ar), .25);
}

.qz-btn-check:disabled,
.qz-btn-show:disabled {
  opacity: .4;
  cursor: default;
}

/* "Show answer" is secondary */
.qz-btn-show {
  background: var(--bg3);
  color: var(--text2);
}

.qz-btn-show:hover:not(:disabled) {
  background: var(--bg2);
  color: var(--text);
}

/* "Try again" is secondary too */
.qz-btn-retry {
  background: var(--bg3);
  color: var(--text2);
}

.qz-btn-retry:hover:not(:disabled) {
  background: var(--bg2);
  color: var(--text);
}

.qz-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.qz-actions:empty {
  display: none;
}

.qz-actions button[hidden] {
  display: none;
}

/* ============================================================
 * Feedback / answer / explanation
 * ============================================================ */
.qz-feedback {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.55;
}

.qz-feedback[hidden] { display: none; }

.qz-fb-ok {
  background: rgba(34, 197, 94, .1);
  border-left: 3px solid #22c55e;
  padding: 10px 14px;
  border-radius: 6px;
}

.qz-fb-no {
  background: rgba(239, 68, 68, .08);
  border-left: 3px solid #ef4444;
  padding: 10px 14px;
  border-radius: 6px;
}

.qz-answer, .qz-explanation {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--bg2);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text2);
  animation: qzReveal .25s ease;
}

.qz-answer[hidden], .qz-explanation[hidden] { display: none; }

.qz-ans-label, .qz-exp-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 6px;
}

.qz-exp-label {
  margin-top: 10px;
}

.qz-ans-body, .qz-exp-body {
  color: var(--text);
}

.qz-ans-body strong, .qz-exp-body strong {
  color: var(--text);
}

@keyframes qzReveal {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.qz-error {
  padding: 12px 16px;
  background: rgba(239, 68, 68, .1);
  border: 1px solid #ef4444;
  border-radius: 8px;
  color: #ef4444;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
}

/* Mobile tweaks */
@media (max-width: 768px) {
  .qz-shell { padding: 16px 18px; }
  .qz-stem { font-size: 14.5px; }
  .qz-input-row { flex-direction: column; }
  .qz-input-row > * { width: 100%; }
  .qz-actions { flex-direction: column; }
  .qz-actions > * { width: 100%; }
}

/* ============================================================
 * Recall Card — flashcard-style retrieval (prompt → reveal → self-rate)
 * ============================================================ */
.qz-recall .qz-stem {
  font-size: 17px;
  margin-bottom: 18px;
}

.qz-rate {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg2);
  border-radius: 8px;
}

.qz-rate[hidden] { display: none; }

.qz-rate-prompt {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text3);
  margin-bottom: 10px;
}

.qz-rate-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.qz-rate-btn {
  flex: 1;
  min-width: 100px;
  padding: 10px 14px;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
}

.qz-rate-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-1px);
}

.qz-rate-btn:disabled {
  opacity: .4;
  cursor: default;
  transform: none;
}

.qz-rate-btn.qz-rate-selected {
  opacity: 1;
  font-weight: 700;
}

.qz-rate-no.qz-rate-selected {
  background: rgba(239, 68, 68, .15);
  border-color: #ef4444;
  color: #ef4444;
}

.qz-rate-partial.qz-rate-selected {
  background: rgba(245, 158, 11, .15);
  border-color: #f59e0b;
  color: #f59e0b;
}

.qz-rate-yes.qz-rate-selected {
  background: rgba(34, 197, 94, .15);
  border-color: #22c55e;
  color: #22c55e;
}

@media (max-width: 768px) {
  .qz-rate-buttons { flex-direction: column; }
  .qz-rate-btn { width: 100%; }
}


.qz-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  gap: 10px;
}

.qz-progress:empty { display: none; }
.qz-progress > [hidden] { display: none; }

/* The badge that shows current state ("First try", "Got it", "N attempts") */
.qz-progress-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.qz-pb-icon {
  font-size: 12px;
  line-height: 1;
}

/* Got it on first try — celebrate quietly */
.qz-pb-first {
  background: rgba(34, 197, 94, .12);
  color: #15803d;
  border-color: rgba(34, 197, 94, .35);
}
[data-theme="dark"] .qz-pb-first {
  background: rgba(34, 197, 94, .18);
  color: #4ade80;
}

/* Got it eventually */
.qz-pb-eventual {
  background: rgba(59, 130, 246, .1);
  color: #1e40af;
  border-color: rgba(59, 130, 246, .35);
}
[data-theme="dark"] .qz-pb-eventual {
  background: rgba(59, 130, 246, .15);
  color: #60a5fa;
}

/* Tried, not yet correct */
.qz-pb-attempted {
  background: rgba(245, 158, 11, .1);
  color: #92400e;
  border-color: rgba(245, 158, 11, .35);
}
[data-theme="dark"] .qz-pb-attempted {
  background: rgba(245, 158, 11, .15);
  color: #fbbf24;
}

/* Per-card reset — small, secondary */
.qz-progress-reset {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text3);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.qz-progress-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Global reset: a small floating button bottom-right of any page with quizzes */
.cb-quiz-global-reset {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  padding: 9px 14px;
  background: var(--bg2);
  color: var(--text3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  transition: all .15s ease;
  opacity: .65;
}

.cb-quiz-global-reset:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(var(--ar), .15);
}

@media (max-width: 768px) {
  .cb-quiz-global-reset {
    bottom: 12px;
    right: 12px;
    font-size: 10px;
    padding: 8px 12px;
  }
}

/* ============================================================
 * Editorial mode — when body has .cb-editorial, quiz cards adopt the
 * same typography rhythm as the rest of the editorial design system.
 * ============================================================ */
.cb-editorial .qz-shell {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 28px 32px;
}

.cb-editorial .qz-label {
  font-family: 'IBM Plex Mono', 'JetBrains Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 2.2px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 12px;
}

.cb-editorial .qz-stem {
  font-family: 'Manrope', 'Manrope', serif;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -.015em;
  line-height: 1.4;
  margin-bottom: 20px;
  color: var(--text);
}

.cb-editorial .qz-recall .qz-stem {
  font-size: 22px;
}

.cb-editorial .qz-ans-label,
.cb-editorial .qz-exp-label,
.cb-editorial .qz-rate-prompt {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 1.8px;
}

.cb-editorial .qz-ans-body,
.cb-editorial .qz-exp-body {
  font-family: 'Inter', 'Manrope', sans-serif;
  font-size: 14.5px;
  line-height: 1.65;
}

.cb-editorial .qz-opt {
  font-family: 'Inter', 'Manrope', sans-serif;
  font-size: 14.5px;
}

.cb-editorial .qz-progress-badge {
  font-family: 'IBM Plex Mono', monospace;
}
