/* ==========================================================================
   CD-IELTS Authentic Matching Sentence Endings Stylesheet
   Replicates official Computer-Delivered IELTS interaction
   Draggable Ending Tokens • Click-to-Place Dropzones • Tactile Return Mechanics
   ========================================================================== */

.cd-ielts-endings-container {
  margin: 1.5rem 0 1rem 0;
  width: 100%;
  clear: both;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* -------------------------------------------------------------
   1. Endings Bank (List of Endings Container)
   ------------------------------------------------------------- */
.endings-bank-card {
  margin-bottom: 1.5rem;
  padding: 1.15rem 1.25rem;
  background-color: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.endings-bank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.endings-bank-title {
  font-weight: 800;
  font-size: 0.875rem;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.endings-bank-badge {
  font-size: 0.725rem;
  font-weight: 700;
  color: #0369a1;
  background-color: #e0f2fe;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #bae6fd;
}

/* Tokens Pool */
.endings-tokens-pool {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* Draggable Ending Token */
.ending-token {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  background-color: #ffffff;
  cursor: grab;
  user-select: none;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ending-token:hover {
  border-color: #0284c7;
  background-color: #f0f9ff;
  box-shadow: 0 3px 8px rgba(2, 132, 199, 0.15);
  transform: translateY(-1px);
}

.ending-token:active {
  cursor: grabbing;
  transform: scale(0.985);
  box-shadow: 0 1px 2px rgba(2, 132, 199, 0.2);
}

.ending-token.dragging {
  opacity: 0.4;
  transform: scale(0.98);
  border-color: #0284c7;
}

/* Click-to-Place Target Mode */
.ending-token.is-selected,
.ending-token.selected-for-place {
  border-color: #0284c7 !important;
  border-width: 2px !important;
  background-color: #e0f2fe !important;
  box-shadow: 0 0 0 3.5px rgba(2, 132, 199, 0.35), 0 4px 12px rgba(2, 132, 199, 0.18) !important;
  transform: translateY(-2px);
  animation: endingTokenPulse 1.6s infinite ease-in-out;
}

.ending-token.is-selected .ending-token-letter,
.ending-token.selected-for-place .ending-token-letter {
  background-color: #0369a1;
  box-shadow: 0 0 0 2px #bae6fd;
  transform: scale(1.08);
}

.ending-token.is-selected .ending-token-text,
.ending-token.selected-for-place .ending-token-text {
  color: #0c4a6e !important;
  font-weight: 600;
}

@keyframes endingTokenPulse {
  0%, 100% {
    border-color: #0284c7;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.35), 0 4px 12px rgba(2, 132, 199, 0.18);
  }
  50% {
    border-color: #38bdf8;
    box-shadow: 0 0 0 5px rgba(56, 189, 248, 0.45), 0 6px 16px rgba(2, 132, 199, 0.25);
  }
}

/* Empty Dropzones when a token is selected and awaiting placement */
.cd-ielts-endings-container.has-selected-token .ending-dropzone:not(.has-placed) {
  border-color: #0284c7 !important;
  background-color: #f0f9ff !important;
  cursor: pointer;
  animation: dropzoneReadyPulse 1.8s infinite ease-in-out;
}

.cd-ielts-endings-container.has-selected-token .ending-dropzone:not(.has-placed):hover {
  background-color: #e0f2fe !important;
  border-color: #0369a1 !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.25);
}

@keyframes dropzoneReadyPulse {
  0%, 100% {
    border-color: #0284c7;
    background-color: #f0f9ff;
  }
  50% {
    border-color: #38bdf8;
    background-color: #e0f2fe;
  }
}

/* Placed / In-Use Token in Bank */
.ending-token.is-used {
  opacity: 0.35;
  filter: grayscale(0.85);
  pointer-events: none;
  border-style: dashed;
  background-color: #f1f5f9;
}

.ending-token-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.825rem;
  color: #ffffff;
  background-color: #0284c7;
  border-radius: 4px;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}

.ending-token-text {
  font-size: 0.9rem;
  color: #1e293b;
  line-height: 1.45;
  flex: 1;
}

/* -------------------------------------------------------------
   2. Sentence Stem Question Rows & Dropzones
   ------------------------------------------------------------- */
.sentence-ending-row {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  padding: 1rem 1.15rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background-color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s ease;
}

.sentence-ending-row:hover {
  border-color: #cbd5e1;
}

.sentence-stem {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #0f172a;
}

.sentence-stem-qnum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  color: #0284c7;
  background-color: #e0f2fe;
  border-radius: 4px;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 0.25rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.sentence-stem-text {
  flex: 1;
  font-weight: 500;
}

/* Inline Dropzone Gap */
.ending-dropzone {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 44px;
  width: 100%;
  padding: 0.35rem 0.65rem;
  border: 1.8px dashed #94a3b8;
  border-radius: 6px;
  background-color: rgba(248, 250, 252, 0.85);
  box-sizing: border-box;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
}

.ending-dropzone:hover:not(.has-placed) {
  border-color: #0284c7;
  background-color: #f0f9ff;
}

.ending-dropzone-placeholder {
  color: #94a3b8;
  font-size: 0.85rem;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Dropzone Awaiting Placement (Click-to-Place Mode) */
.ending-dropzone.awaiting-placement {
  border: 2px dashed #0284c7 !important;
  background-color: #eff6ff !important;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
  animation: endingDropzonePulse 1.6s infinite;
}

@keyframes endingDropzonePulse {
  0%, 100% { border-color: #0284c7; background-color: #eff6ff; }
  50% { border-color: #38bdf8; background-color: #f0f9ff; }
}

/* Drag Over Target State */
.ending-dropzone.drag-over {
  border: 2px solid #0284c7 !important;
  background-color: #e0f2fe !important;
  transform: scale(1.005);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.2);
}

/* Placed Ending Card inside Dropzone */
.placed-ending-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.65rem;
  padding: 0.35rem 0.6rem;
  background-color: #ffffff;
  border: 1.5px solid #0284c7;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.placed-ending-left {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex: 1;
}

.placed-ending-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  color: #ffffff;
  background-color: #0284c7;
  border-radius: 4px;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.25rem;
  flex-shrink: 0;
}

.placed-ending-text {
  font-size: 0.875rem;
  color: #0f172a;
  line-height: 1.4;
  font-weight: 500;
}

/* Remove / Return Button */
.placed-ending-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background-color: #f1f5f9;
  color: #64748b;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
  line-height: 1;
  padding: 0;
}

.placed-ending-remove-btn:hover {
  background-color: #fee2e2;
  color: #dc2626;
  transform: scale(1.1);
}

/* -------------------------------------------------------------
   3. Review / Results State (Checking Answers)
   ------------------------------------------------------------- */
.ending-dropzone.is-correct {
  border: 1.8px solid #16a34a !important;
  background-color: #f0fdf4 !important;
}

.ending-dropzone.is-correct .placed-ending-card {
  border-color: #16a34a;
  background-color: #f0fdf4;
}

.ending-dropzone.is-correct .placed-ending-letter {
  background-color: #16a34a;
}

.ending-dropzone.is-incorrect {
  border: 1.8px solid #dc2626 !important;
  background-color: #fef2f2 !important;
}

.ending-dropzone.is-incorrect .placed-ending-card {
  border-color: #dc2626;
  background-color: #fef2f2;
}

.ending-dropzone.is-incorrect .placed-ending-letter {
  background-color: #dc2626;
}

.ending-review-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  margin-top: 0.35rem;
}

.ending-review-badge.correct {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}

.ending-review-badge.incorrect {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

/* -------------------------------------------------------------
   4. Dark Mode Adaptation
   ------------------------------------------------------------- */
.theme-dark .endings-bank-card,
.theme-contrast .endings-bank-card {
  background-color: #1e293b;
  border-color: #475569;
}

.theme-dark .endings-bank-title,
.theme-contrast .endings-bank-title {
  color: #f8fafc;
}

.theme-dark .ending-token,
.theme-contrast .ending-token {
  background-color: #0f172a;
  border-color: #475569;
}

.theme-dark .ending-token-text,
.theme-contrast .ending-token-text {
  color: #e2e8f0;
}

.theme-dark .ending-token:hover,
.theme-contrast .ending-token:hover {
  background-color: #1e293b;
  border-color: #38bdf8;
}

.theme-dark .sentence-ending-row,
.theme-contrast .sentence-ending-row {
  background-color: #0f172a;
  border-color: #334155;
}

.theme-dark .sentence-stem,
.theme-contrast .sentence-stem {
  color: #f8fafc;
}

.theme-dark .ending-dropzone,
.theme-contrast .ending-dropzone {
  background-color: #1e293b;
  border-color: #475569;
}

.theme-dark .placed-ending-card,
.theme-contrast .placed-ending-card {
  background-color: #0f172a;
  border-color: #38bdf8;
}

.theme-dark .placed-ending-text,
.theme-contrast .placed-ending-text {
  color: #f8fafc;
}

.theme-dark .placed-ending-remove-btn,
.theme-contrast .placed-ending-remove-btn {
  background-color: #334155;
  color: #94a3b8;
}

/* Hide original inputs cleanly */
.cd-ielts-endings-hidden,
div.q-item.cd-ielts-endings-hidden,
.q-matching-item.cd-ielts-endings-hidden,
[id^="container-q"].cd-ielts-endings-hidden,
.cd-ielts-raw-item-hidden,
div.q-item.cd-ielts-raw-item-hidden,
.q-matching-item.cd-ielts-raw-item-hidden,
[id^="container-q"].cd-ielts-raw-item-hidden {
  display: none !important;
}

/* Review Mode Focus Pulse for Explanations */
.expl-focus-highlight {
  animation: explPulseHighlight 2s ease-out forwards;
}

@keyframes explPulseHighlight {
  0% {
    box-shadow: 0 0 0 4px rgba(2, 132, 199, 0.45);
    transform: scale(1.01);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(2, 132, 199, 0.25);
  }
  100% {
    box-shadow: none;
    transform: scale(1);
  }
}


/* Mobile Sentence Endings Hardening (<= 640px) */
@media (max-width: 640px) {
  .cd-ielts-endings-wrapper {
    padding: 0.75rem !important;
  }
  .endings-bank-tray {
    padding: 0.65rem 0.75rem !important;
  }
  .ending-stem-row {
    padding: 0.75rem !important;
    gap: 0.5rem !important;
  }
  .ending-dropzone {
    min-height: 38px !important;
    padding: 0.25rem 0.45rem !important;
  }
  .placed-ending-card {
    padding: 0.25rem 0.45rem !important;
    font-size: 0.8125rem !important;
  }
}
