/* ============================================
   Interactive Exercise Widgets - Premium LeetCode-style
   ============================================ */

/* === Exercise Widget Container === */
.exercise-widget {
  position: relative;
  margin: 2rem 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--md-code-bg-color);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* === Exercise Header === */
.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.exercise-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.exercise-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.exercise-id {
  font-weight: 500;
  opacity: 0.9;
}

.exercise-controls {
  display: flex;
  gap: 0.5rem;
}

.exercise-controls button {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.exercise-controls button:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

/* === Exercise Body - Split Pane === */
.exercise-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 350px;
}

@media (max-width: 900px) {
  .exercise-body {
    grid-template-columns: 1fr;
  }
}

/* === Editor Pane === */
.editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

@media (max-width: 900px) {
  .editor-pane {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
}

.editor-header {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.file-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: var(--md-code-bg-color);
  border-radius: 6px 6px 0 0;
  font-size: 0.85rem;
  font-family: var(--md-code-font-family);
  color: var(--md-code-fg-color);
}

.file-icon {
  font-size: 1rem;
}

.code-editor-container {
  flex: 1;
  overflow: auto;
}

.code-editor-container .cm-editor {
  height: 100%;
  min-height: 280px;
}

.code-editor-container .cm-scroller {
  font-family: 'Fira Code', 'JetBrains Mono', monospace !important;
  font-size: 14px;
  line-height: 1.6;
}

/* Fallback textarea */
.fallback-editor {
  width: 100%;
  height: 100%;
  min-height: 280px;
  padding: 1rem;
  border: none;
  background: var(--md-code-bg-color);
  color: var(--md-code-fg-color);
  font-family: 'Fira Code', monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
}

.fallback-editor:focus {
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: -2px;
}

/* === Results Pane === */
.results-pane {
  display: flex;
  flex-direction: column;
  background: var(--md-default-bg-color);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.05);
  font-weight: 600;
  color: var(--md-default-fg-color);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.test-summary {
  font-size: 0.85rem;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
}

.test-summary.all-passed {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.test-summary.some-failed {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
}

.test-cases-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.test-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--md-default-fg-color--light);
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem;
}

/* === Test Case Cards === */
.test-case {
  margin-bottom: 0.75rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.test-case:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.test-case.passed {
  border-left: 4px solid #10b981;
}

.test-case.failed {
  border-left: 4px solid #ef4444;
}

.test-case-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(0, 0, 0, 0.03);
  font-weight: 500;
  font-size: 0.85rem;
}

.test-status {
  font-size: 1rem;
}

.test-case-body {
  padding: 0.75rem;
  background: white;
}

[data-md-color-scheme="slate"] .test-case-body {
  background: rgba(255, 255, 255, 0.03);
}

.test-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.test-row:last-child {
  margin-bottom: 0;
}

.test-label {
  flex-shrink: 0;
  width: 70px;
  font-weight: 500;
  color: var(--md-default-fg-color--light);
}

.test-value {
  flex: 1;
  font-family: var(--md-code-font-family);
  background: rgba(0, 0, 0, 0.05);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  word-break: break-all;
}

.test-value.expected {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.test-value.correct {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.test-value.incorrect {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.error-text {
  color: #dc2626;
}

/* === Test Error Display === */
.test-error {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.error-icon {
  font-size: 1.5rem;
}

.error-content {
  flex: 1;
}

.error-content pre {
  margin: 0.5rem 0 0 0;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* === Exercise Footer === */
.exercise-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.05);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.hint-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 193, 7, 0.15);
  border-radius: 8px;
  font-size: 0.85rem;
  color: #b45309;
  max-width: 60%;
}

[data-md-color-scheme="slate"] .hint-display {
  background: rgba(255, 193, 7, 0.2);
  color: #fbbf24;
}

.hint-icon {
  font-size: 1rem;
}

.action-buttons {
  display: flex;
  gap: 0.5rem;
}

.run-tests-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.run-tests-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

.run-tests-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.run-icon {
  font-size: 0.8rem;
}

.shortcut {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 0.25rem;
  padding: 0.15rem 0.4rem;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* === Loading Overlay === */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
}

/* === Success Animation === */
.exercise-widget.success-animation {
  animation: success-pulse 0.5s ease;
}

@keyframes success-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15); }
  50% { box-shadow: 0 4px 30px rgba(16, 185, 129, 0.5); }
}

/* === Confetti Effect === */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 20;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  top: -10px;
  left: calc(var(--x) * 100%);
  animation: confetti-fall 2s ease-out var(--delay) forwards;
  border-radius: 2px;
}

.confetti:nth-child(even) {
  background: linear-gradient(135deg, #10b981, #059669);
}

.confetti:nth-child(3n) {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(500px) rotate(720deg);
    opacity: 0;
  }
}

/* === Dark Mode Adjustments === */
[data-md-color-scheme="slate"] .exercise-widget {
  border-color: rgba(255, 255, 255, 0.1);
}

[data-md-color-scheme="slate"] .results-pane {
  background: #1e1e1e;
}

[data-md-color-scheme="slate"] .results-header {
  background: rgba(255, 255, 255, 0.05);
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-md-color-scheme="slate"] .test-case {
  border-color: rgba(255, 255, 255, 0.1);
}

[data-md-color-scheme="slate"] .test-case-header {
  background: rgba(255, 255, 255, 0.05);
}

[data-md-color-scheme="slate"] .test-value {
  background: rgba(255, 255, 255, 0.05);
}

[data-md-color-scheme="slate"] .exercise-footer {
  background: rgba(255, 255, 255, 0.03);
  border-top-color: rgba(255, 255, 255, 0.1);
}

/* === Responsive Design === */
@media (max-width: 600px) {
  .exercise-header {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
  }

  .exercise-controls {
    width: 100%;
    justify-content: center;
  }

  .exercise-footer {
    flex-direction: column;
    gap: 0.75rem;
  }

  .hint-display {
    max-width: 100%;
  }

  .action-buttons {
    width: 100%;
  }

  .run-tests-btn {
    width: 100%;
    justify-content: center;
  }

  .shortcut {
    display: none;
  }
}

/* === Print Styles === */
@media print {
  .exercise-widget {
    page-break-inside: avoid;
  }

  .exercise-controls,
  .action-buttons,
  .loading-overlay {
    display: none !important;
  }
}

/* === Accessibility === */
@media (prefers-reduced-motion: reduce) {
  .exercise-widget *,
  .loading-spinner,
  .confetti {
    animation: none !important;
    transition: none !important;
  }
}

.exercise-widget button:focus,
.exercise-widget .cm-editor:focus-within {
  outline: 3px solid var(--md-accent-fg-color);
  outline-offset: 2px;
}
