/* === Interactive Exercise Blocks === */

.exercise {
  margin: 2rem 0;
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
  box-shadow: 0 2px 12px var(--shadow);
}

.exercise-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

.exercise-header h4 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-heading);
}

.exercise-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.exercise-badge-predict {
  background: rgba(122, 162, 247, 0.2);
  color: var(--accent);
}

.exercise-badge-fill {
  background: rgba(158, 206, 106, 0.2);
  color: var(--accent-green);
}

.exercise-badge-free {
  background: rgba(187, 154, 247, 0.2);
  color: var(--accent-secondary);
}

.exercise-prompt {
  padding: 0.75rem 1.25rem 0;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 1.6;
}

.exercise-editor {
  padding: 0.75rem 1.25rem;
}

.exercise-editor .cm-editor {
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  max-height: 400px;
  overflow: auto;
}

.exercise-editor .cm-editor.cm-focused {
  outline: none;
  border-color: var(--accent);
}

/* Schema block for SQL exercises */
.exercise-schema {
  margin: 0 1.25rem;
}

.exercise-schema summary {
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
  background: none;
  border: none;
}

.exercise-schema summary:hover {
  color: var(--accent);
}

.exercise-schema pre {
  margin: 0.5rem 0;
  font-size: 12px;
}

/* Controls row */
.exercise-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.25rem 0.75rem;
  flex-wrap: wrap;
}

.exercise-controls button {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.exercise-controls button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.exercise-controls .run-btn,
.exercise-controls .check-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.exercise-controls .run-btn:hover,
.exercise-controls .check-btn:hover {
  opacity: 0.85;
}

.exercise-controls .run-btn:disabled,
.exercise-controls .check-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Predict input */
.predict-input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text-primary);
  flex: 1;
  min-width: 150px;
  max-width: 300px;
}

.predict-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Output panel */
.exercise-output {
  margin: 0 1.25rem;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.3s;
}

.exercise-output:empty {
  display: none;
}

.exercise-output pre {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 13px;
  line-height: 1.5;
  border: none;
  border-radius: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.exercise-output.success {
  border: 1px solid var(--accent-green);
  background: rgba(158, 206, 106, 0.08);
}

.exercise-output.success pre {
  color: var(--accent-green);
  background: transparent;
}

.exercise-output.error {
  border: 1px solid var(--accent-red);
  background: rgba(247, 118, 142, 0.08);
}

.exercise-output.error pre {
  color: var(--accent-red);
  background: transparent;
}

.exercise-output.neutral {
  border: 1px solid var(--border);
  background: var(--code-bg);
}

.exercise-output.neutral pre {
  color: var(--text-primary);
  background: transparent;
}

/* Hint and solution */
.exercise-hint,
.exercise-solution {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 14px;
  display: none;
}

.exercise-hint.visible,
.exercise-solution.visible {
  display: block;
}

.exercise-hint {
  background: rgba(255, 158, 100, 0.06);
  color: var(--text-primary);
}

.exercise-solution {
  background: rgba(158, 206, 106, 0.06);
}

.exercise-solution pre {
  margin: 0.5rem 0 0;
}

/* Bottom padding in exercise */
.exercise > *:last-child {
  margin-bottom: 0;
  padding-bottom: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
  .exercise-controls {
    gap: 0.4rem;
  }
  .exercise-controls button {
    padding: 5px 12px;
    font-size: 12px;
  }
  .predict-input {
    max-width: 100%;
  }
}

/* Print — hide interactive elements */
@media print {
  .exercise-controls,
  .exercise-output,
  .exercise-hint,
  .exercise-solution,
  .exercise-schema {
    display: none;
  }
  .exercise {
    border: 1px solid #ccc;
  }
}

/* === Quiz Pool === */

.quiz-pool {
  margin: 2rem 0;
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
  box-shadow: 0 2px 12px var(--shadow);
}

.quiz-pool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quiz-pool-title {
  font-weight: 600;
  color: var(--text-heading);
  font-size: 0.95rem;
}

.quiz-pool-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Language toggle button group */
.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.lang-btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border: none;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all 0.2s;
}

.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

.lang-btn:hover:not(.active) {
  color: var(--accent);
}

/* Next question button */
.next-question-btn {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transition: all 0.2s;
}

.next-question-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Exercises inside a quiz pool — pool provides the card chrome */
.quiz-pool .exercise {
  border: none;
  box-shadow: none;
  margin: 0;
  border-radius: 0;
  background: transparent;
}

/* Responsive */
@media (max-width: 768px) {
  .quiz-pool-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .quiz-pool-controls {
    width: 100%;
  }
}

/* Print — hide quiz pool interactive controls */
@media print {
  .quiz-pool-header .quiz-pool-controls {
    display: none;
  }
}
