/* Shared status colours for correct / incorrect across map, main MCQ, sidebar */
:root {
  --er-mcq-correct-bg:      #d3f9d8;
  --er-mcq-correct-border:  #51cf66;
  --er-mcq-correct-text:    #2b8a3e;

  --er-mcq-incorrect-bg:    #ffe3e3;
  --er-mcq-incorrect-border:#ff6b6b;
  --er-mcq-incorrect-text:  #c92a2a;
}

/* ---------------- Ribbon ---------------- */

.sticky-top.er-mcq-ribbon {
  z-index: 500;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* ---------------- Question map (offcanvas) ---------------- */

.er-mcq-map-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Bubble wrapper to keep spacing tight */
.er-mcq-bubble-wrapper {
  position: relative;
}

/* Map bubbles: small rounded tiles with Q number + subject code */
.btn.er-mcq-bubble {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;

  width: 3.3rem;
  height: 3.3rem;

  padding: 0.15rem 0 0.1rem; /* no horizontal padding */
  border-radius: 0.9rem;
  border-width: 2px;

  font-size: 0.75rem;
  line-height: 1.1;
  text-align: center;

  text-decoration: none;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    background-color 0.1s ease,
    border-color 0.1s ease,
    color 0.1s ease;
}

.btn.er-mcq-bubble:hover,
.btn.er-mcq-bubble:focus {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Big number in the middle */
.er-mcq-bubble-qnum {
  display: block;
  font-weight: 600;
  font-size: 1.05rem;
  margin-top: 0.55rem;
}

/* Subject footer line – full width, no background strip, sits at bottom */
.er-mcq-bubble-subject {
  margin-top: auto; /* push to bottom */
  width: 100%;
  box-sizing: border-box;

  padding: 0.04rem 0 0.16rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;

  background-color: transparent;
  color: inherit;

  border-radius: 0 0 0.7rem 0.7rem;
  border-top: none;
}

/* Bookmark star overlay */
.er-mcq-bubble-star {
  position: absolute;
  top: 0.05rem;
  right: 0.15rem;
  font-size: 0.9rem;
  color: #f5b700;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.25);
}

/* Status colours for bubbles */
.btn.er-mcq-bubble.er-mcq-status-not_attempted {
  border-color: #dee2e6;
  background-color: #f8f9fa;
  color: #495057;
}

.btn.er-mcq-bubble.er-mcq-status-correct {
  border-color: var(--er-mcq-correct-border);
  background-color: var(--er-mcq-correct-bg);
  color: var(--er-mcq-correct-text);
}

.btn.er-mcq-bubble.er-mcq-status-incorrect {
  border-color: var(--er-mcq-incorrect-border);
  background-color: var(--er-mcq-incorrect-bg);
  color: var(--er-mcq-incorrect-text);
}

/* Legend row in map */
.er-mcq-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.75rem;
}

.er-mcq-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.er-mcq-legend-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  border: 2px solid #dee2e6;
  background-color: #f8f9fa;
}

.er-mcq-legend-dot.status-not_attempted {
  border-color: #dee2e6;
  background-color: #f8f9fa;
}

.er-mcq-legend-dot.status-correct {
  border-color: var(--er-mcq-correct-border);
  background-color: var(--er-mcq-correct-bg);
}

.er-mcq-legend-dot.status-incorrect {
  border-color: var(--er-mcq-incorrect-border);
  background-color: var(--er-mcq-incorrect-bg);
}

.er-mcq-legend-star {
  font-size: 0.8rem;
  color: #f5b700;
}

/* ---------------- Answer insight card (stats + explanation) ---------------- */

.er-mcq-insight {
  /* Remove all card styling - blend seamlessly with background */
  background-color: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  animation: er-mcq-insight-fade 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  /* Tighten the vertical gap to the options above */
  margin-top: 0.4rem !important;
  margin-bottom: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;

  /* Match main question padding:
     - mobile: 1rem (same as .p-3)
     - md+   : 1.5rem (same as .p-md-4)
  */
  padding-top: 0.6rem !important;
  padding-right: 1rem !important;
  padding-bottom: 1rem !important;
  padding-left: 1rem !important;

  /* Ensure the insight card is contained */
  max-width: 100%;
  overflow: visible; /* Allow content to show but don't let it push sidebar */
  box-sizing: border-box;
  /* Prevent insight card from expanding beyond its container */
  position: relative;
}

@media (min-width: 768px) {
  .er-mcq-insight {
    padding-left: 1.5rem !important;
    padding-right: 1.5rem !important;
  }
}

@keyframes er-mcq-insight-fade {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.er-mcq-insight-summary {
  border-bottom: 1px solid #f1f3f5;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.er-insight-pill {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #e9ecef;
  color: #495057;
}

.er-insight-result-correct {
  background-color: var(--er-mcq-correct-bg);
  color: var(--er-mcq-correct-text);
}

.er-insight-result-incorrect {
  background-color: var(--er-mcq-incorrect-bg);
  color: var(--er-mcq-incorrect-text);
}

/* Explanation text takes centre-stage - STRICTLY CONTAINED to prevent pushing sidebar */
.er-mcq-explanation {
  font-size: 0.9rem;
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  overflow-wrap: break-word !important;
  word-wrap: break-word !important;
  /* CRITICAL: Prevent expansion beyond parent */
  min-width: 0 !important;
  /* Horizontal overflow: scroll if needed */
  overflow-x: auto !important;
  /* Vertical: allow natural height but contain horizontal expansion */
  overflow-y: visible;
  /* Ensure it respects parent container bounds */
  position: relative;
  /* Force containment */
  display: block;
}

/* Fix clearfix class that might cause layout issues */
.er-mcq-explanation .clearfix {
  clear: none !important;
  overflow: hidden !important;
  max-width: 100% !important;
}

/* Ensure field wrapper doesn't expand beyond bounds */
.er-mcq-explanation .field,
.er-mcq-explanation .field__item,
.er-mcq-explanation .text-formatted {
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  overflow-wrap: break-word !important;
  word-wrap: break-word !important;
  min-width: 0 !important;
  overflow: hidden !important; /* Hide overflow instead of expanding */
}

.er-mcq-explanation p:last-child {
  margin-bottom: 0;
}

/* Constrain all direct and nested elements - CRITICAL to prevent expansion */
.er-mcq-explanation * {
  max-width: 100%;
  box-sizing: border-box;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Ensure lists and links wrap properly */
.er-mcq-explanation ol,
.er-mcq-explanation ul {
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  min-width: 0 !important;
  overflow: hidden !important; /* Prevent list from expanding */
  padding-left: 1.5rem !important; /* Ensure proper list indentation */
}

.er-mcq-explanation li {
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  min-width: 0 !important;
  /* Force list items to wrap */
  display: list-item !important;
  word-break: break-word !important;
}

/* Break long URLs - CRITICAL for preventing expansion */
.er-mcq-explanation a {
  word-break: break-all !important;
  overflow-wrap: anywhere !important;
  max-width: 100% !important;
  display: inline !important; /* Changed from inline-block to inline for better wrapping */
  box-sizing: border-box !important;
  /* Force wrapping at any point */
  white-space: normal !important;
  hyphens: auto !important;
}

/* Ensure links in lists also wrap */
.er-mcq-explanation li a,
.er-mcq-explanation ol a,
.er-mcq-explanation ul a {
  word-break: break-all !important;
  overflow-wrap: anywhere !important;
  display: inline !important;
  white-space: normal !important;
  max-width: 100% !important;
}

/* Ensure paragraphs don't expand */
.er-mcq-explanation p {
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  min-width: 0 !important;
}

/* Tables - make scrollable if too wide */
.er-mcq-explanation table {
  width: 100% !important;
  max-width: 100% !important;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
}

.er-mcq-explanation table td,
.er-mcq-explanation table th {
  white-space: normal;
  word-wrap: break-word;
}

/* Images */
.er-mcq-explanation img {
  max-width: 100% !important;
  height: auto !important;
  display: block;
}

/* Pre/code blocks */
.er-mcq-explanation pre {
  max-width: 100%;
  overflow-x: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.er-mcq-explanation code {
  max-width: 100%;
  overflow-x: auto;
  word-wrap: break-word;
}

/* Stats strip is visually light and compact */
.er-mcq-insight-stats {
  border-color: #f1f3f5;
  padding-top: 0.5rem !important;
  margin-top: 0.4rem !important;
}

.er-mcq-chart-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #868e96;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.er-mcq-chart-subtitle {
  font-size: 0.7rem;
  color: #adb5bd;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

/* Chart.js canvases – slim and refined */

.er-mcq-chart {
  width: 100%;
  max-width: 180px;
  display: block;
  margin: 0 auto;
}

/* Donut wrapper + center label - smaller and more refined */

.er-mcq-donut-wrapper {
  position: relative;
  display: inline-block;
  width: 75px;
  height: 75px;
  margin: 0 auto;
}

.er-mcq-donut-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.er-mcq-donut-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #212529;
  line-height: 1.2;
}

.er-mcq-donut-caption {
  font-size: 0.6rem;
  font-weight: 400;
  color: #868e96;
  margin-top: 0.1rem;
}

/* Make chart sections more compact */
.er-mcq-insight-stats .row {
  margin-top: 0.5rem;
}

.er-mcq-insight-stats .col-12 {
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}

/* Responsive tweaks */

@media (max-width: 576px) {
  .er-mcq-chart {
    max-width: 100%;
  }

  .er-mcq-donut-wrapper {
    width: 85px;
    height: 85px;
  }
}

/* ---- Change-set dropdown tweaks ---- */

.er-mcq-set-dropdown {
  min-width: 600px;
}

/* Force dropdown to ALWAYS open downward - FINAL CSS OVERRIDE */
/* Prevent dropup class from being applied */
.dropdown:has(#erMcqSetDropdown) {
  /* Remove dropup if accidentally added */
}

.dropdown:has(#erMcqSetDropdown).dropup {
  /* Force it to be regular dropdown, not dropup */
}

/* Force dropdown menu position - override ALL possible states */
#erMcqSetDropdown + .dropdown-menu.er-mcq-set-dropdown,
.dropdown:has(#erMcqSetDropdown) .dropdown-menu.er-mcq-set-dropdown,
.dropdown-menu.er-mcq-set-dropdown,
.er-mcq-set-dropdown,
.er-mcq-set-dropdown.show,
.er-mcq-set-dropdown[data-popper-placement],
.er-mcq-set-dropdown[data-popper-placement^="top"],
.er-mcq-set-dropdown[data-popper-placement^="bottom"],
.dropdown.dropup .er-mcq-set-dropdown,
.dropdown:not(.dropup) .er-mcq-set-dropdown {
  position: absolute !important;
  top: 100% !important;
  bottom: auto !important;
  left: auto !important;
  right: 0 !important;
  transform: translate(0, 10px) !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  /* Override any Popper positioning */
  will-change: auto !important;
}

/* Specifically override dropup behavior if class exists */
.dropdown.dropup .er-mcq-set-dropdown {
  top: 100% !important;
  bottom: auto !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

.er-mcq-set-form {
  text-align: left;
}

/* Exam + year side-by-side */
.er-mcq-set-row {
  display: flex;
  gap: 0.75rem;
}

.er-mcq-set-row .er-mcq-set-exam {
  flex: 3;
}

.er-mcq-set-row .er-mcq-set-year {
  flex: 2;
}

/* Go button: full width, visually centred */
.er-mcq-set-actions {
  margin-top: 0.75rem;
}

.er-mcq-set-actions .btn {
  width: 100%;
  display: block;
}

/* ========================================
   Prevent explanation from pushing sidebar down
   ======================================== */

/* Contain explanation within its space - prevent it from expanding beyond container */
.er-mcq-explanation {
  max-height: none; /* Allow natural height but contain overflow */
  overflow-y: visible; /* Allow content to show */
  overflow-x: auto; /* Horizontal scroll if needed */
  word-wrap: break-word;
  overflow-wrap: break-word;
  /* Ensure it doesn't break out of parent container */
  position: relative;
  box-sizing: border-box;
}

/* Ensure insight card container stays within bounds - don't let it push layout */
.er-mcq-insight {
  position: relative;
  max-width: 100% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  /* CRITICAL: Prevent expansion beyond parent */
  min-width: 0 !important;
  overflow: hidden !important; /* Hide any overflow instead of expanding */
}

/* Prevent any child elements from breaking out of insight card */
.er-mcq-insight * {
  max-width: 100% !important;
  box-sizing: border-box !important;
  min-width: 0 !important;
}
