/* ========================================
   mkdocs-superquiz - THEME CLAIR
   ======================================== */

/* ========================================
   VARIABLES GÉNÉRALES
   ======================================== */
:root {
  --mkq-primary: #1976d2;
  --mkq-success: #4caf50;
  --mkq-error: #f44336;
  --mkq-warning: #ff9800;
  --mkq-bg: #ffffff;
  --mkq-border: #e0e0e0;
  --mkq-text: #212121;
  --mkq-text-secondary: #757575;
  --mkq-hover: #f5f5f5;
  --mkq-shadow: rgba(0, 0, 0, 0.1);
}

/* ========================================
   STYLES COMMUNS - TOUS LES QUIZ
   ======================================== */
.mkdocs-superquiz {
  background: var(--mkq-bg);
  border: 2px solid var(--mkq-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 2px 4px var(--mkq-shadow);
  
  .admonition-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--mkq-text);
    margin-bottom: 1rem;
  }

  .MathJax {
    margin-left:  .4em;
    margin-right: .4em;
  }
}

/* ========================================
   ICÔNES DE VERROUILLAGE
   ======================================== */
.mkq-unlock-btn,
.mkq-lock-indicator {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  padding: 0.25rem 0.5rem;
  transition: transform 0.2s, opacity 0.2s;
  
  &.unlocked {
    color: var(--mkq-success);
    cursor: default;
    
    &:hover {
      transform: none;
    }
  }
  
  &.locked {
    color: var(--mkq-warning);
    cursor: pointer;
    
    &:hover {
      transform: scale(1.2);
    }
  }
  
  &.locked-permanent {
    color: var(--mkq-error);
    cursor: not-allowed;
    opacity: 0.6;
    
    &:hover {
      transform: none;
    }
  }
}

.mkq-lock-indicator {
  display: inline-block;
  cursor: default;
}

/* ========================================
   QUESTIONS
   ======================================== */
.mkq-question {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--mkq-hover);
  border-radius: 6px;
  
  .mkq-question-text {
    font-weight: 500;
    font-size: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-wrap: wrap;
    
    .mkq-number {
      color: var(--mkq-primary);
      font-weight: 700;
      margin-right: 0.5rem;
    }
  }
  
  .mkq-answers {
    margin-left: 2rem;
  }
}

/* ========================================
   RICH CONTENT (images, iframes, markdown)
   preamble  : before all questions in the quiz
   per-question rich content : between question text and answers
   ======================================== */
.mkq-rich-content {
  margin: 0.5rem 0 1rem 0;
  font-size: 1rem;
  
  img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    margin: 0.5rem auto;
  }
  
  iframe {
    max-width: 100%;
    display: block;
    margin: 0.5rem auto;
    border: none;
    border-radius: 4px;
  }
  
  p {
    margin: 0.4rem 0;
  }
}

/* Preamble (before all questions) gets a bit more bottom spacing */
.mkdocs-superquiz > .mkq-rich-content {
  margin-bottom: 1.25rem;
}

/* ========================================
   RÉPONSES (CHOIX)
   ======================================== */
.mkq-answer {
  display: flex;
  align-items: center;
  padding: 0.1rem;
  margin: 0.1rem 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
  font-size:1rem;
  
  &:hover {
    background: var(--mkq-border);
  }
  
  input[type="checkbox"],
  input[type="radio"] {
    margin-right: 0.75rem;
    cursor: pointer;
  }
  
  .mkq-answer-text {
    flex: 1;
    color: var(--mkq-text);
  }
  
  .mkq-answer-feedback {
    margin-left: 0.5rem;
    font-weight: 600;
    
    &.correct {
      color: var(--mkq-success);
      &::before {
        content: "✓ ";
      }
    }
    
    &.incorrect {
      color: var(--mkq-error);
      &::before {
        content: "✗ ";
      }
    }
  }
  
  &.correct {
    background: rgba(76, 175, 80, 0.1);
    border-left: 3px solid var(--mkq-success);
  }
  
  &.incorrect {
    background: rgba(244, 67, 54, 0.1);
    border-left: 3px solid var(--mkq-error);
  }
}

/* ========================================
   INPUTS (GAPFILL)
   ======================================== */
.mkq-gap-input {
  min-width: 150px;
  padding: 0.25rem 0.5rem;
  border: 2px solid var(--mkq-border);
  border-radius: 4px;
  font-size: 1rem;
  transition: border-color 0.2s;
  
  &:focus {
    outline: none;
    border-color: var(--mkq-primary);
  }
  
  &.correct {
    border-color: var(--mkq-success);
    background: rgba(76, 175, 80, 0.05);
  }
  
  &.incorrect {
    border-color: var(--mkq-error);
    background: rgba(244, 67, 54, 0.05);
  }
}


/* ========================================
   GAPFILL CORRECTIONS - CUSTOM MATHJAX DROPDOWN
   ======================================== */

/* Wrapper for label + dropdown */
.mkq-gap-correction-wrapper {
  display: inline-flex;
  flex-direction: column;
  position: relative;
  min-width: 180px;
  vertical-align: middle;
  margin: 0 0.25rem;
}

/* Red strikethrough badge — floats above the dropdown */
.mkq-gap-wrong-label {
  position:    absolute;
  top:         -0.7rem;
  left:        0.75rem;
  background:  var(--mkq-bg);
  padding:     0 0.5rem;
  font-size:   0.75rem;
  font-weight: 600;
  color:       var(--mkq-error);
  z-index:     2;
  animation:   mkq-slide-down 0.3s ease-out;

  opacity: 0.85;

  s {
    text-decoration: none;
  }

  mjx-container {
    position: relative;
    display: inline-block;

    &::after {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      left: -0.2em;
      right: -0.2em;

      background: linear-gradient(
        -45deg,
        transparent 0,
        transparent calc(50% - 2px),
        currentColor 50%,
        transparent calc(50% + 2px),
        transparent 100%
      );

      opacity: 0.7;
      pointer-events: none;
    }
  }

  &:not(:has(mjx-container)) {
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    text-decoration-color: currentColor;
  }
}

/* Only when the badge contains MathJax, lift it up a bit */
.mkq-gap-wrong-label:has(mjx-container) {
  top: 0;
  transform: translateY(-67%);
}


/* Custom Select Container */
.mkq-custom-select {
  position: relative;
  width: 100%;
  display: inline-block;
}

/* Button */
.mkq-custom-select-btn {
  width: 100%;
  text-align: left;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 2px solid var(--mkq-success);
  border-radius: 6px;
  background: rgba(76, 175, 80, 0.05);
  color: var(--mkq-text);
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(76, 175, 80, 0.15);
  transition: all 0.2s;
  
  &:hover {
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.25);
  }
  
  &:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
  }
}

.mkq-custom-select-value {
  display: inline-block;
  min-height: 1.2em;
}

/* Arrow */
.mkq-custom-select-arrow {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mkq-success);
  font-size: 1rem;
  pointer-events: none;
  transition: transform 0.2s;
}

.mkq-custom-select[aria-expanded="true"] .mkq-custom-select-arrow {
  transform: translateY(-50%) rotate(180deg);
}

/* Listbox */
.mkq-custom-select-listbox {
  position: absolute;
  z-index: 100;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem;
  border-radius: 6px;
  border: 2px solid var(--mkq-success);
  background: var(--mkq-bg);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  display: none;
  max-height: 240px;
  overflow-y: auto;
}

.mkq-custom-select[aria-expanded="true"] .mkq-custom-select-listbox {
  display: block;
}

/* Options */
.mkq-custom-select-option {
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  
  &:hover {
    background: rgba(76, 175, 80, 0.1);
  }
  
  &[aria-selected="true"] {
    background: rgba(76, 175, 80, 0.2);
    font-weight: 500;
  }
}

/* Animation */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Correct input styling */
.mkq-gap-input.correct {
  border-color: var(--mkq-success);
  background: rgba(76, 175, 80, 0.05);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

/* ========================================
   CUSTOM DROPDOWN (MathJax compatible)
   ======================================== */
.mkq-custom-dropdown {
  display: inline-block;
  position: relative;
  min-width: 200px;
  vertical-align: middle;
  margin: 0 0.5rem;
}

.mkq-custom-dropdown-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--mkq-border);
  border-radius: 6px;
  background: var(--mkq-bg);
  color: var(--mkq-text);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  
  &:hover {
    border-color: var(--mkq-primary);
  }
}

.mkq-custom-dropdown-value {
  flex: 1;
  text-align: left;
}

.mkq-custom-dropdown-arrow {
  margin-left: 0.5rem;
  color: var(--mkq-text-secondary);
}

.mkq-custom-dropdown-options {
  display: none;
  position: absolute;
  z-index: 100;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0;
  background: var(--mkq-bg);
  border: 2px solid var(--mkq-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--mkq-shadow);
  max-height: 300px;
  overflow-y: auto;
}

.mkq-custom-dropdown-option {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
  
  &:hover {
    background: var(--mkq-hover);
  }
  
  &.selected {
    background: rgba(25, 118, 210, 0.1);
    font-weight: 500;
  }
}

.mkq-custom-dropdown.correct .mkq-custom-dropdown-btn {
  border-color: var(--mkq-success);
  background: rgba(76, 175, 80, 0.05);
}

.mkq-custom-dropdown.incorrect .mkq-custom-dropdown-btn {
  border-color: var(--mkq-error);
  background: rgba(244, 67, 54, 0.05);
}

// Dropdown correction

/* Dropdown correction wrapper - mirrors gapfill style */
.mkq-dropdown-correction-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    position: relative;
}

/* Reuse gapfill wrong label for dropdown too */
.mkq-custom-dropdown.correct .mkq-custom-dropdown-btn {
    border-color: var(--mkq-correct-color, #4caf50);
    background-color: var(--mkq-correct-bg, #e8f5e9);
    color: var(--mkq-correct-color, #2e7d32);
}

.mkq-custom-dropdown.incorrect .mkq-custom-dropdown-btn {
    border-color: var(--mkq-incorrect-color, #f44336);
    background-color: var(--mkq-incorrect-bg, #ffebee);
    color: var(--mkq-incorrect-color, #c62828);
}


/* ========================================
   ACTIONS ET SCORE
   ======================================== */
.quiz-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--mkq-border);
  display: flex;
  justify-content: space-between;
  align-items: center;

  .mkq-validate-btn {
    background: var(--mkq-primary);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.2s, transform 0.1s;
    position: relative;
    z-index: 3;
    
    &:hover {
      background: darken(#1976d2, 10%);
      transform: translateY(-2px);
    }
    
    &:active {
      transform: translateY(0);
    }
  }

  .mkq-score {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    
    &.good {
      color: var(--mkq-success);
      background: rgba(76, 175, 80, 0.1);
    }
    
    &.medium {
      color: var(--mkq-warning);
      background: rgba(255, 152, 0, 0.1);
    }
    
    &.bad {
      color: var(--mkq-error);
      background: rgba(244, 67, 54, 0.1);
    }
  }
}

/* ========================================
   MODAL DE DÉBLOCAGE
   ======================================== */
.mkq-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  
  &.active {
    display: flex;
  }
  
  .mkq-modal-content {
    background: var(--mkq-bg);
    padding: 2rem;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 4px 20px var(--mkq-shadow);
    position: relative;
    
    h3 {
      margin-top: 0;
      color: var(--mkq-text);
    }
    
    .qr-code-section {
      text-align: center;
      margin: 1.5rem 0;
      
      #qr-code-container {
        display: inline-block;
        padding: 1rem;
        background: white;
        border-radius: 8px;
      }
    }
    
    .unlock-input-section {
      margin-top: 1.5rem;
      
      label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        color: var(--mkq-text);
      }
      
      input[type="text"] {
        width: 100%;
        padding: 0.75rem;
        border: 2px solid var(--mkq-border);
        border-radius: 6px;
        font-size: 1rem;
        margin-bottom: 1rem;
        
        &:focus {
          outline: none;
          border-color: var(--mkq-primary);
        }
      }
      
      button {
        width: 100%;
        background: var(--mkq-primary);
        color: white;
        border: none;
        padding: 0.75rem;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 6px;
        cursor: pointer;
        
        &:hover {
          background: darken(#1976d2, 10%);
        }
      }
    }
    
    .mkq-modal-close {
      position: absolute;
      top: 1rem;
      right: 1rem;
      background: transparent;
      border: none;
      font-size: 1.5rem;
      cursor: pointer;
      color: var(--mkq-text-secondary);
      
      &:hover {
        color: var(--mkq-text);
      }
    }
  }
}

/* ========================================
   SECTION MCQUIZ - CHOIX MULTIPLES
   ======================================== */
.mkdocs-superquiz[data-quiz-type="mcquiz"] {
  border-color: #2196f3;
  
  .admonition-title {
    color: #2196f3;
  }
  
  .mkq-number {
    color: #2196f3;
  }
}

/* ========================================
   SECTION SCQUIZ - CHOIX UNIQUE
   ======================================== */
.mkdocs-superquiz[data-quiz-type="scquiz"] {
  border-color: #ff9800;
  
  .admonition-title {
    color: #ff9800;
  }
  
  .mkq-number {
    color: #ff9800;
  }
}

/* ========================================
   SECTION GAPFILL - À TROUS
   ======================================== */
.mkdocs-superquiz[data-quiz-type="gapfill"] {
  border-color: #9c27b0;
  
  .admonition-title {
    color: #9c27b0;
  }
  
  .mkq-number {
    color: #9c27b0;
  }
  
  .mkq-gap-input {
    display: inline-block;
    margin: 0 0.25rem;
    vertical-align: baseline;
  }
}

/* ========================================
   CORRECTIONS
   ======================================== */
.mkq-question-correction {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(33, 150, 243, 0.05);
  border-left: 4px solid var(--mkq-primary);
  border-radius: 4px;
  
  &::before {
    content: "💡 Correction : ";
    font-weight: 600;
    color: var(--mkq-primary);
  }
}

/* ========================================
   PAGE BUTTONS (Unlock All + Reset All)
   ======================================== */

/* Container for both buttons */
.mkq-page-buttons {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

/* Make h1 a flex container when it contains the buttons */
.md-content h1:has(.mkq-page-buttons) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* Base button styles (shared) */
.mkq-refresh-page-btn,
.mkq-unlock-page-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  
  &:active {
    transform: translateY(0);
  }
  
  .mkq-btn-icon {
    font-size: 1.2em;
    line-height: 1;
  }
  
  .mkq-btn-text {
    line-height: 1;
  }
}

/* Unlock Page button (primary blue) */
.mkq-unlock-page-btn {
  background: var(--mkq-primary);
  
  &:hover {
    background: #1565c0;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
}

/* Refresh button (secondary green) */
.mkq-refresh-page-btn {
  background: var(--mkq-success);
  
  &:hover {
    background: #43a047;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
  .mkdocs-superquiz {
    padding: 1rem;
  }
  
  .mkq-question {
    padding: 0.75rem;
  }
  
  .mkq-answers {
    margin-left: 1rem;
  }
  
  .quiz-actions {
    flex-direction: column;
    gap: 1rem;
    
    .mkq-validate-btn,
    .mkq-score {
      width: 100%;
    }
  }
  
  .mkq-modal-content {
    padding: 1.5rem;
  }

  /* Page buttons responsive */
  .md-content h1:has(.mkq-page-buttons) {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .mkq-page-buttons {
    align-self: stretch;
    width: 100%;
    
    button {
      flex: 1;
    }
  }

  /* Rich content responsive */
  .mkq-rich-content {
    iframe {
      width: 100%;
      height: auto;
      aspect-ratio: 16 / 9;
    }
  }
}