/* ==========================================================================
   CD-IELTS Authentic Matching Matrix Stylesheet (Features / Names / Information)
   Harmonized with English Mastery Hub Design System
   Modern Slate/Sky Tokens • Pill Badges • Tactile Halo Radios • Full Dark Theme
   ========================================================================== */

.cd-ielts-matrix-container {
  margin: 1.5rem 0 1.25rem 0;
  width: 100%;
  max-width: 100%;
  clear: both;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Outer Border Box matching English Mastery Hub aesthetic */
.cd-ielts-matching-matrix,
.question.matching_names,
.question.matching-names {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background-color: #ffffff;
  overflow: hidden;
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cd-ielts-matching-matrix:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
}

/* Header Row */
.cd-ielts-matching-matrix .list-answers,
.question.matching_names .list-answers,
.question.matching-names .list-answers {
  display: flex;
  background-color: #f8fafc;
  border-bottom: 1.5px solid #e2e8f0;
  font-weight: 700;
  user-select: none;
}

.cd-ielts-matching-matrix .list-answers .label,
.question.matching_names .list-answers .label,
.question.matching-names .list-answers .label {
  flex: 1 1 50%;
  width: 50%;
  padding: 12px 16px;
  border-right: 1px solid #e2e8f0;
  font-size: 0.8rem;
  font-weight: 800;
  color: #475569;
  display: flex;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cd-ielts-matching-matrix .list-answers .list,
.question.matching_names .list-answers .list,
.question.matching-names .list-answers .list {
  display: flex;
  flex: 1 1 50%;
  width: 50%;
}

.cd-ielts-matching-matrix .list-answers .list .number-alphabet,
.question.matching_names .list-answers .list .number-alphabet,
.question.matching-names .list-answers .list .number-alphabet {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 12px 0;
  border-right: 1px solid #e2e8f0;
  color: #0f172a;
  background-color: #f8fafc;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.cd-ielts-matching-matrix .list-answers .list .number-alphabet:last-child,
.question.matching_names .list-answers .list .number-alphabet:last-child,
.question.matching-names .list-answers .list .number-alphabet:last-child {
  border-right: none;
}

/* Question Rows */
.cd-ielts-matching-matrix .item-question,
.question.matching_names .item-question,
.question.matching-names .item-question {
  display: flex;
  border-bottom: 1px solid #f1f5f9;
  background-color: #ffffff;
  transition: background-color 0.15s ease;
}

.cd-ielts-matching-matrix .item-question:last-child,
.question.matching_names .item-question:last-child,
.question.matching-names .item-question:last-child {
  border-bottom: none;
}

.cd-ielts-matching-matrix .item-question:hover {
  background-color: #f8fafc;
}

/* Left Label: Statement text & Question number */
.cd-ielts-matching-matrix .item-question .label,
.question.matching_names .item-question .label,
.question.matching-names .item-question .label {
  flex: 1 1 50%;
  width: 50%;
  padding: 14px 16px;
  border-right: 1px solid #e2e8f0;
  font-size: 0.925rem;
  line-height: 1.55;
  color: #1e293b;
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
}

/* Question Number Badge - Official Hub Pill Style */
.cd-ielts-matrix-qnum,
.cd-ielts-matrix-qnum.q-num-pill {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 1.65rem !important;
  min-width: 1.65rem !important;
  max-width: 1.65rem !important;
  height: 1.65rem !important;
  border-radius: 9999px !important;
  background: #e0f2fe !important;
  color: #0284c7 !important;
  font-size: 0.775rem !important;
  font-weight: 800 !important;
  flex-shrink: 0 !important;
  margin-right: 0.65rem !important;
  margin-top: 0.05rem !important;
  padding: 0 !important;
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.12) !important;
  user-select: none !important;
  line-height: 1 !important;
}

.cd-ielts-matrix-text {
  flex: 1;
  font-weight: 500;
  color: #1e293b;
  line-height: 1.55;
}

/* Right List: Matrix Columns */
.cd-ielts-matching-matrix .item-question .list,
.question.matching_names .item-question .list,
.question.matching-names .item-question .list {
  display: flex;
  flex: 1 1 50%;
  width: 50%;
}

/* Individual Cell with Radio */
.cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check,
.question.matching_names .item-question .list .form-check,
.question.matching-names .item-question .list .form-check {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  cursor: pointer;
  border-right: 1px solid #f1f5f9;
  position: relative;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 52px;
  background-color: #ffffff;
}

.cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:last-child,
.question.matching_names .item-question .list .form-check:last-child,
.question.matching-names .item-question .list .form-check:last-child {
  border-right: none;
}

/* Hover cell effect */
.cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:hover:not(.active) {
  background-color: #f0f9ff;
}

/* Active / Selected Cell Highlight (Subtle Sky Tint Harmonized with Hub Style) */
.cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check.active,
.cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:has(input:checked),
.question.matching_names .item-question .list .form-check.active,
.question.matching_names .item-question .list .form-check:has(input:checked),
.question.matching-names .item-question .list .form-check.active,
.question.matching-names .item-question .list .form-check:has(input:checked) {
  background-color: #e0f2fe !important;
  box-shadow: inset 0 0 0 1px #bae6fd;
}

/* Radio Input Styling - Tactile Modern Halo */
.cd-ielts-matching-matrix .form-check-input,
.question.matching_names .form-check-input,
.question.matching-names .form-check-input {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  outline: none;
  background-color: #ffffff;
  cursor: pointer;
  margin: 0;
  position: relative;
  display: inline-block;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-ielts-matching-matrix .form-check:hover .form-check-input,
.question.matching_names .form-check:hover .form-check-input,
.question.matching-names .form-check:hover .form-check-input {
  border-color: #0284c7;
  transform: scale(1.08);
}

.cd-ielts-matching-matrix .form-check-input:checked,
.question.matching_names .form-check-input:checked,
.question.matching-names .form-check-input:checked {
  border-color: #0284c7;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.18);
}

.cd-ielts-matching-matrix .form-check-input:checked::after,
.question.matching_names .form-check-input:checked::after,
.question.matching-names .form-check-input:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #0284c7;
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.3);
}

/* Radio Focus Ring */
.cd-ielts-matching-matrix .form-check-input:focus-visible {
  outline: 2px solid #0284c7;
  outline-offset: 2px;
}

/* Hidden Select Container for 100% Zero-Regression Form Sync */
.cd-ielts-hidden-select {
  position: absolute !important;
  opacity: 0 !important;
  pointer-events: none !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
}

/* Converted Original Question Items & Redundant Question Lists - Strictly Hidden */
.cd-ielts-raw-item-hidden,
div.q-item.cd-ielts-raw-item-hidden,
.q-matching-item.cd-ielts-raw-item-hidden,
.cd-ielts-converted-item,
div.q-item.cd-ielts-converted-item,
.q-matching-item.cd-ielts-converted-item,
.cd-ielts-converted-container {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Options Reference Card (e.g. List of People / Research Findings) */
.cd-ielts-options-ref-card {
  margin-bottom: 1.5rem;
  padding: 1.15rem 1.25rem;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.cd-ielts-options-ref-card .ref-card-title {
  font-weight: 800;
  font-size: 0.85rem;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.5rem;
}

.cd-ielts-options-ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.6rem 1.25rem;
}

.cd-ielts-options-ref-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.925rem;
  color: #334155;
  padding: 0.3rem 0;
}

.cd-ielts-options-ref-item strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  background-color: #e0f2fe;
  color: #0284c7;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* Review / Results State (When student clicks "Check All" or Finishes Exam) */
.cd-ielts-matching-matrix.reviewed .item-question.is-correct {
  background-color: #f0fdf4;
}

.cd-ielts-matching-matrix.reviewed .item-question.is-incorrect {
  background-color: #fef2f2;
}

.cd-ielts-matching-matrix.reviewed .form-check.is-correct-choice {
  background-color: #dcfce7 !important;
  box-shadow: inset 0 0 0 2px #16a34a;
}

.cd-ielts-matching-matrix.reviewed .form-check.is-wrong-choice {
  background-color: #fee2e2 !important;
  box-shadow: inset 0 0 0 2px #dc2626;
}

.cd-ielts-matrix-feedback-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  margin-left: 0.5rem;
  margin-top: 0.25rem;
}

.cd-ielts-matrix-feedback-badge.correct {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}

.cd-ielts-matrix-feedback-badge.incorrect {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

/* Dark Mode Adaptation (for Real Test Environment & Global Dark Themes) */
.theme-dark .cd-ielts-matching-matrix,
.theme-contrast .cd-ielts-matching-matrix,
html[data-theme='dark'] .cd-ielts-matching-matrix {
  border-color: #334155;
  background-color: #0f172a;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.theme-dark .cd-ielts-matching-matrix .list-answers,
.theme-contrast .cd-ielts-matching-matrix .list-answers,
html[data-theme='dark'] .cd-ielts-matching-matrix .list-answers {
  background-color: #1e293b;
  border-bottom-color: #334155;
}

.theme-dark .cd-ielts-matching-matrix .list-answers .label,
.theme-dark .cd-ielts-matching-matrix .list-answers .list .number-alphabet,
.theme-contrast .cd-ielts-matching-matrix .list-answers .label,
.theme-contrast .cd-ielts-matching-matrix .list-answers .list .number-alphabet,
html[data-theme='dark'] .cd-ielts-matching-matrix .list-answers .label,
html[data-theme='dark'] .cd-ielts-matching-matrix .list-answers .list .number-alphabet {
  color: #f8fafc;
  border-right-color: #334155;
  background-color: #1e293b;
}

.theme-dark .cd-ielts-matching-matrix .item-question,
.theme-contrast .cd-ielts-matching-matrix .item-question,
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question {
  background-color: #0f172a;
  border-bottom-color: #1e293b;
}

.theme-dark .cd-ielts-matching-matrix .item-question:hover,
.theme-contrast .cd-ielts-matching-matrix .item-question:hover,
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question:hover {
  background-color: #1e293b;
}

.theme-dark .cd-ielts-matching-matrix .item-question .label,
.theme-contrast .cd-ielts-matching-matrix .item-question .label,
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question .label {
  color: #e2e8f0;
  border-right-color: #334155;
}

.theme-dark .cd-ielts-matrix-text,
.theme-contrast .cd-ielts-matrix-text,
html[data-theme='dark'] .cd-ielts-matrix-text {
  color: #e2e8f0;
}

.theme-dark .cd-ielts-matrix-qnum,
.theme-contrast .cd-ielts-matrix-qnum,
html[data-theme='dark'] .cd-ielts-matrix-qnum,
.theme-dark .cd-ielts-matrix-qnum.q-num-pill,
.theme-contrast .cd-ielts-matrix-qnum.q-num-pill,
html[data-theme='dark'] .cd-ielts-matrix-qnum.q-num-pill {
  background: #0369a1 !important;
  color: #bae6fd !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
}

.theme-dark .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check,
.theme-contrast .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check,
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check {
  border-right-color: #1e293b;
  background-color: #0f172a;
}

.theme-dark .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:hover:not(.active),
.theme-contrast .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:hover:not(.active),
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check:hover:not(.active) {
  background-color: #1e293b;
}

.theme-dark .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check.active,
.theme-contrast .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check.active,
html[data-theme='dark'] .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check.active {
  background-color: #0c4a6e !important;
  box-shadow: inset 0 0 0 1px #0284c7;
}

.theme-dark .cd-ielts-matching-matrix .form-check-input,
.theme-contrast .cd-ielts-matching-matrix .form-check-input,
html[data-theme='dark'] .cd-ielts-matching-matrix .form-check-input {
  border-color: #475569;
  background-color: #1e293b;
}

.theme-dark .cd-ielts-matching-matrix .form-check:hover .form-check-input,
.theme-contrast .cd-ielts-matching-matrix .form-check:hover .form-check-input,
html[data-theme='dark'] .cd-ielts-matching-matrix .form-check:hover .form-check-input {
  border-color: #38bdf8;
}

.theme-dark .cd-ielts-matching-matrix .form-check-input:checked,
.theme-contrast .cd-ielts-matching-matrix .form-check-input:checked,
html[data-theme='dark'] .cd-ielts-matching-matrix .form-check-input:checked {
  border-color: #38bdf8;
  background-color: #1e293b;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

.theme-dark .cd-ielts-matching-matrix .form-check-input:checked::after,
.theme-contrast .cd-ielts-matching-matrix .form-check-input:checked::after,
html[data-theme='dark'] .cd-ielts-matching-matrix .form-check-input:checked::after {
  background-color: #38bdf8;
  box-shadow: 0 1px 2px rgba(56, 189, 248, 0.4);
}

.theme-dark .cd-ielts-options-ref-card,
.theme-contrast .cd-ielts-options-ref-card,
html[data-theme='dark'] .cd-ielts-options-ref-card {
  background-color: #1e293b;
  border-color: #334155;
}

.theme-dark .cd-ielts-options-ref-card .ref-card-title,
.theme-contrast .cd-ielts-options-ref-card .ref-card-title,
html[data-theme='dark'] .cd-ielts-options-ref-card .ref-card-title {
  color: #f8fafc;
  border-bottom-color: #334155;
}

.theme-dark .cd-ielts-options-ref-item,
.theme-contrast .cd-ielts-options-ref-item,
html[data-theme='dark'] .cd-ielts-options-ref-item {
  color: #cbd5e1;
}

.theme-dark .cd-ielts-options-ref-item strong,
.theme-contrast .cd-ielts-options-ref-item strong,
html[data-theme='dark'] .cd-ielts-options-ref-item strong {
  background-color: #0369a1;
  color: #bae6fd;
}

/* Mobile & Tablet Responsiveness */
@media (max-width: 640px) {
  .cd-ielts-matching-matrix {
    font-size: 0.85rem;
  }

  .cd-ielts-matching-matrix .list-answers .label,
  .cd-ielts-matching-matrix .item-question .label {
    width: 45%;
    flex: 1 1 45%;
    padding: 10px 10px;
    font-size: 0.825rem;
  }

  .cd-ielts-matching-matrix .list-answers .list,
  .cd-ielts-matching-matrix .item-question .list {
    width: 55%;
    flex: 1 1 55%;
  }

  .cd-ielts-matching-matrix .item-question .list .form-check, .cd-ielts-matching-matrix .item-question .list .btn-check {
    min-height: 44px;
  }

  .cd-ielts-matching-matrix .form-check-input {
    width: 17px;
    height: 17px;
  }

  .cd-ielts-matrix-qnum,
  .cd-ielts-matrix-qnum.q-num-pill {
    width: 1.45rem !important;
    min-width: 1.45rem !important;
    max-width: 1.45rem !important;
    height: 1.45rem !important;
    font-size: 0.725rem !important;
    margin-right: 0.45rem !important;
  }
}



/* Responsive Column Minimum Widths and Touch Target Ergonomics */
.cd-ielts-matching-matrix .list-answers .list .number-alphabet,
.cd-ielts-matching-matrix .item-question .list .form-check,
.cd-ielts-matching-matrix .item-question .list .btn-check {
  min-width: 44px !important;
  min-height: 48px !important;
  cursor: pointer !important;
  user-select: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

/* Tactile Active Press Animation on Click */
.cd-ielts-matching-matrix .item-question .list .form-check:active,
.cd-ielts-matching-matrix .item-question .list .btn-check:active {
  transform: scale(0.96);
  background-color: #e0f2fe !important;
}

.cd-ielts-matching-matrix .item-question .list .form-check:active .form-check-input,
.cd-ielts-matching-matrix .item-question .list .btn-check:active .form-check-input {
  transform: scale(0.92);
}

/* Sticky Left Question Column on Tablets, Mobile & Split-Screen Viewports */
@media (max-width: 1024px) {
  .cd-ielts-matching-matrix {
    min-width: 620px;
  }
  .cd-ielts-matching-matrix .list-answers .label,
  .cd-ielts-matching-matrix .item-question .label {
    min-width: 220px !important;
    position: sticky !important;
    left: 0 !important;
    z-index: 10 !important;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.05) !important;
  }
  .cd-ielts-matching-matrix .list-answers .label {
    background-color: #f8fafc !important;
  }
  .cd-ielts-matching-matrix .item-question .label {
    background-color: #ffffff !important;
  }
  .theme-dark .cd-ielts-matching-matrix .list-answers .label,
  [data-theme='dark'] .cd-ielts-matching-matrix .list-answers .label {
    background-color: #1e293b !important;
  }
  .theme-dark .cd-ielts-matching-matrix .item-question .label,
  [data-theme='dark'] .cd-ielts-matching-matrix .item-question .label {
    background-color: #0f172a !important;
  }
}

@media (max-width: 640px) {
  .cd-ielts-matrix-container {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0 0.75rem 0 !important;
  }
  .cd-ielts-matching-matrix {
    min-width: 440px !important;
  }
  .cd-ielts-matching-matrix .list-answers .label,
  .cd-ielts-matching-matrix .item-question .label {
    min-width: 135px !important;
    max-width: 150px !important;
    padding: 8px 10px !important;
    font-size: 0.75rem !important;
    line-height: 1.3 !important;
  }
  .cd-ielts-matching-matrix .list-answers .list,
  .cd-ielts-matching-matrix .item-question .list {
    flex: 1 1 auto;
  }
  .cd-ielts-matching-matrix .list-answers .list .col,
  .cd-ielts-matching-matrix .item-question .list .form-check,
  .cd-ielts-matching-matrix .item-question .list .btn-check {
    min-width: 36px !important;
    padding: 8px 4px !important;
  }
  .cd-ielts-matching-matrix .item-question .list .form-check-input {
    width: 18px !important;
    height: 18px !important;
  }
}
