/* Frontend-only enhancements for QSM quiz pages (prototype)
 * - Non-destructive: wraps existing markup if it matches expected selectors
 * - One-question-at-a-time with Prev/Next
 * - Sticky top bar: timer, progress, flag
 * - Self-mark textbox per question (local only)
 */

:root {
  --fm-accent: #4bc0c0; /* rgba(75, 192, 192, 1) */
  --fm-accent-20: rgba(75, 192, 192, 0.2);
  --fm-danger: #ff6384; /* rgba(255, 99, 132, 1) */
  --fm-danger-20: rgba(255, 99, 132, 0.2);
  --fm-bg: #0f172a; /* slate-900 */
  --fm-fg: #e2e8f0; /* slate-200 */
  --fm-card-bg: #f8fafc; /* fallback slate-50 */
  --fm-card-border: rgba(15, 23, 42, 0.15);
  --fm-card-shadow: 0 10px 20px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.05);
  /* Theme-overridable primary/accent */
  --primary-color: #f1f5f9; /* slate-100 */
  --accent-color: #e2e8f0;  /* slate-200 */
}

/* Enhancement shell */
.fm-quiz-enhancer {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.fm-quiz-toolbar {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
  color: var(--fm-fg);
  border-bottom: 1px solid rgba(148,163,184,0.2);
  backdrop-filter: saturate(120%) blur(6px);
}

/* Content area fills remaining viewport below toolbar */
.fm-quiz-content {
  flex: 1 1 auto;
  overflow: visible; /* card scrolls */
  min-height: 0; /* critical for flex children to allow scrolling */
  touch-action: pan-y; /* ensure vertical gestures scroll the container */
  position: relative;
  width: 100%;
}

/* When enhanced, freeze the body scroll so the content container is the scrollport */
/* no body lock */

.fm-quiz-toolbar .fm-left,
.fm-quiz-toolbar .fm-right {
  display: contents;
  gap: 10px;
  align-items: center;
}

.fm-quiz-counter {
  font-size: 14px;
  font-weight: 600;
  color: #2b3543;
  text-align: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.8);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

/* Make radio button answers display inline */
.qmn_radio_answers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.qmn_mc_answer_wrap {
  display: inline-block;
  margin: 0;
}

.fm-quiz-progress {
  height: 16px;
  background: rgba(148,163,184,0.25);
  border-radius: 999px;
  overflow: hidden;
  width: 400px;
}

.fm-quiz-progress > span {
  display: block;
  height: 100%;
  background: var(--fm-accent);
  width: 0%;
  transition: width 400ms ease;
}

.fm-quiz-btn {
  appearance: none;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(2,6,23,0.2);
  color: var(--fm-fg);
  padding: 6px 20px 6px 20px !important;
  border-radius: 3px;
  font-size: 10px !important;
  cursor: pointer;
  text-transform: none !important;
  font-family: inherit !important;
}

.fm-quiz-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Make radio button answers display inline */
.qmn_radio_answers {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.qmn_mc_answer_wrap {
  display: inline-block;
  margin: 0;
}

/* Radio-as-button styles */
.fm-radio-btn {
  display: inline-block;
  padding: 6px 20px 6px 20px !important;
  margin: 1px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 10px !important;
  color: #334155;
  text-align: center;
  min-width: 40px;
  text-transform: none !important;
  font-family: inherit !important;
}

.fm-radio-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.fm-radio-btn[aria-pressed="true"] {
  background: #3b82f6;
  border-color: #2563eb;
  color: white;
  font-weight: 600;
}

.fm-radio-btn[aria-pressed="true"]:hover {
  background: #2563eb;
  transform: translateY(-1px);
}

/* Question container management (visibility controlled via .fm-hidden) */

.fm-hidden { display: none !important; }
.fm-quiz-enhancer .qsm-question-wrapper {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
  border: 1px solid var(--fm-card-border);
  border-radius: 12px;
  padding: 16px 16px 12px;
  box-shadow: var(--fm-card-shadow);
  transition: box-shadow 260ms ease, transform 260ms ease, opacity 260ms ease;
  will-change: transform, opacity;
  margin: 14px 0;
  /* Height is managed by JS via max-height on active card; card scrolls */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.fm-quiz-enhancer .qsm-question-wrapper:hover {
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12), 0 4px 10px rgba(15, 23, 42, 0.06);
}

/* Self mark field */
.fm-self-mark {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.fm-self-mark input[type="number"] {
  width: 50px !important;
  border: 1px solid rgba(148,163,184,0.4) !important;
  border-radius: 4px !important;
  padding: 4px 6px !important;
  font-size: 14px !important;
  box-sizing: border-box !important;
}
.fm-self-mark input[type="number"] {
  width: 90px;
}

/* Flag */
.fm-flagged-badge {
  display: inline-block;
  margin-left: 8px;
  background: var(--fm-danger-20);
  color: var(--fm-fg);
  border: 1px solid var(--fm-danger);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 12px;
}

/* Animations */
@keyframes fmSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes fmFlipIn {
  from { opacity: 0; transform: perspective(800px) rotateX(-90deg); transform-origin: top; }
  to { opacity: 1; transform: perspective(800px) rotateX(0deg); transform-origin: top; }
}

@keyframes fmFlipOut {
  from { opacity: 1; transform: perspective(800px) rotateX(0deg); transform-origin: top; }
  to { opacity: 0; transform: perspective(800px) rotateX(90deg); transform-origin: top; }
}

.fm-anim-enter { animation: fmSlideIn 420ms ease both; }
.fm-anim-exit { animation: fmSlideOut 360ms ease both; }

/* Optional flip variant (not default) */
.fm-anim-flip-enter { animation: fmFlipIn 520ms ease both; }
.fm-anim-flip-exit { animation: fmFlipOut 460ms ease both; }

/* Question title styling to match Mark yourself styling */
.fm-quiz-enhancer .mlw_qmn_new_question {
  display: block !important;
  font-family: 'Lato', Sans-serif !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  color: white !important;
  background-color: #28a745 !important;
  padding: 8px !important;
  margin-bottom: 1em !important;
  border-radius: 5px !important;
}

/* Hide QSM hint */
.fm-quiz-enhancer .qsm-hint,
.fm-quiz-enhancer .qsm_hint,
.fm-quiz-enhancer .mlw_qmn_hint_link {
  display: none !important;
}

/* Hide question number span */
.fm-quiz-enhancer .mlw_qmn_question_number {
  display: none !important;
}

/* Solution display styling to match question title but with green background */
.fm-quiz-enhancer .quick-question-res-p.qsm-correct-answer-info {
  display: block !important;
  font-family: 'Lato', Sans-serif !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  color: white !important;
  background-color: green !important;
  padding: 0 !important;
  padding-left: 8px !important;
  margin-bottom: 1em !important;
  border-radius: 5px !important;
}

/* Remove padding from quick-question-res-p elements */
.fm-quiz-enhancer .quick-question-res-p {
  padding: 0 !important;
}

/* Show Solution button styling - green background */
.fm-quiz-enhancer .fm-show-solution-btn {
  background-color: green !important;
  color: white !important;
  border: none !important;
}

/* Hide quiz content initially and show spinner */
.qsm-page {
  opacity: 0 !important;
  visibility: hidden !important;
  transition: opacity 0.3s ease !important;
}

.qsm-page.fm-quiz-ready {
  opacity: 1 !important;
  visibility: visible !important;
}

/* Quiz loading spinner */
.fm-quiz-loading {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  min-height: 200px !important;
  flex-direction: column !important;
}

.fm-quiz-spinner {
  width: 40px !important;
  height: 40px !important;
  border: 4px solid #f3f3f3 !important;
  border-top: 4px solid var(--e-global-color-accent) !important;
  border-radius: 50% !important;
  animation: fm-spin 1s linear infinite !important;
  margin-bottom: 16px !important;
}

@keyframes fm-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.fm-quiz-loading-text {
  font-family: 'Lato', Sans-serif !important;
  font-size: 14px !important;
  color: #666 !important;
  text-align: center !important;
}

/* Quiz category tags - show and style as discrete colorful tags */
.fm-quiz-enhancer .quiz-cat {
  display: block !important;
  text-align: right !important;
  margin: 0.5em 0 !important;
  clear: both !important;
}

.fm-quiz-enhancer .fm-quiz-tags {
  text-align: right !important;
  line-height: 1.2 !important;
}

.fm-quiz-enhancer .fm-quiz-tag {
  font-family: 'Lato', Sans-serif !important;
  font-size: 10px !important;
  font-weight: 500 !important;
  padding: 2px 6px !important;
  margin: 2px 3px 2px 0 !important;
  border-radius: 3px !important;
  display: inline-block !important;
  text-transform: capitalize !important;
}

/* Special styling for Random Questions tag */
.fm-quiz-enhancer .fm-quiz-tag[data-random="true"] {
  background-color: #ff6b6b !important;
  font-weight: 600 !important;
  animation: pulse-random 2s infinite !important;
}

@keyframes pulse-random {
  0% { 
    opacity: 1;
    transform: scale(1);
  }
  50% { 
    opacity: 0.8;
    transform: scale(1.05);
  }
  100% { 
    opacity: 1;
    transform: scale(1);
  }
}

/* Style Back to Practice Tool link to match our buttons */
.fm-quiz-enhancer a[href*="practice"] {
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  border: 1px solid rgba(148,163,184,0.35) !important;
  background: rgba(2,6,23,0.05) !important;
  color: #0f172a !important;
  padding: 4px 6px !important;
  border-radius: 4px !important;
  font-size: 11px !important;
  cursor: pointer !important;
  margin: 3px 4px 3px 0 !important;
  transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease, transform 120ms ease !important;
  text-decoration: none !important;
  box-shadow: none !important;
  line-height: normal !important;
  text-align: left !important;
}
.fm-quiz-enhancer a[href*="practice"]:hover {
  background: rgba(2,6,23,0.08) !important;
}
.fm-quiz-enhancer a[href*="practice"]:active {
  transform: translateY(1px) !important;
}

/* Accessibility: respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .fm-anim-enter,
  .fm-anim-exit,
  .fm-anim-flip-enter,
  .fm-anim-flip-exit {
    animation: none !important;
  }
}
