/* Python Exercise - Monaco Editor + Pyodide Integration */

/* Main container */
.python-exercise-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 2rem 0;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  overflow: hidden;
  background: #1e1e1e;
}

.dark .python-exercise-container {
  border-color: #374151;
}

/* Exercise header */
.python-exercise-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, #1e1e1e 0%, #252526 100%);
  border-bottom: 1px solid #3c3c3c;
}

.python-exercise-header .title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  color: #e5e7eb;
  font-size: 1rem;
}

.python-exercise-header .title svg {
  width: 1.25rem;
  height: 1.25rem;
  color: #3b82f6;
}

.python-exercise-header .header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.python-exercise-header .language-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: #3b82f6;
  color: white;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

/* Fullscreen button */
.fullscreen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: #374151;
  border: 1px solid #4b5563;
  border-radius: 0.375rem;
  color: #9ca3af;
  cursor: pointer;
  transition: all 0.2s;
}

.fullscreen-btn:hover {
  background: #4b5563;
  color: #e5e7eb;
  border-color: #6b7280;
}

.fullscreen-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

.fullscreen-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* Split view for editor and output */
.python-exercise-split {
  display: flex;
  flex-direction: column;
  min-height: 400px;
}

@media (min-width: 1024px) {
  .python-exercise-split {
    flex-direction: row;
  }
}

/* Editor panel */
.python-editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid #3c3c3c;
}

.python-editor-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

.python-editor-panel .file-tabs {
  display: flex;
  gap: 0.25rem;
}

.python-editor-panel .file-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #1e1e1e;
  color: #9ca3af;
  border: none;
  border-radius: 0.375rem 0.375rem 0 0;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
}

.python-editor-panel .file-tab.active {
  background: #1e1e1e;
  color: #e5e7eb;
  border-bottom: 2px solid #3b82f6;
}

.python-editor-panel .file-tab:hover:not(.active) {
  background: #2d2d2d;
}

.python-editor-panel .file-tab svg {
  width: 1rem;
  height: 1rem;
  color: #3b82f6;
}

.python-editor-panel .file-tab .tab-name {
  flex: 1;
}

.python-editor-panel .file-tab .tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  padding: 0;
  background: transparent;
  border: none;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 0.25rem;
}

.python-editor-panel .file-tab .tab-close:hover {
  background: #ef4444;
  color: white;
}

.python-editor-panel .file-tab .tab-close svg {
  width: 0.75rem;
  height: 0.75rem;
  color: currentColor;
}

.python-editor-panel .file-tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: 1px dashed #4b5563;
  border-radius: 0.375rem;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s;
}

.python-editor-panel .file-tab-add:hover {
  background: #2d2d2d;
  border-color: #3b82f6;
  color: #3b82f6;
}

.python-editor-panel .file-tab-add svg {
  width: 1rem;
  height: 1rem;
}

.python-editor-container {
  flex: 1;
  min-height: 300px;
  position: relative;
}

/* Output panel */
.python-output-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #1e1e1e;
}

.python-output-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

.python-output-panel .panel-header span {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #9ca3af;
  font-size: 0.875rem;
  font-weight: 500;
}

.python-output-panel .panel-header svg {
  width: 1rem;
  height: 1rem;
}

.python-output-content {
  flex: 1;
  padding: 1rem;
  font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #d4d4d4;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 200px;
  max-height: 400px;
}

/* Output states */
.python-output-content .output-success {
  color: #4ade80;
}

.python-output-content .output-error {
  color: #f87171;
}

.python-output-content .output-warning {
  color: #fbbf24;
}

.python-output-content .output-info {
  color: #60a5fa;
}

/* Action buttons */
.python-exercise-actions {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  background: #252526;
  border-top: 1px solid #3c3c3c;
}

.python-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.python-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.python-btn svg {
  width: 1rem;
  height: 1rem;
}

.python-btn-run {
  background: #22c55e;
  color: white;
}

.python-btn-run:hover:not(:disabled) {
  background: #16a34a;
}

.python-btn-run.loading {
  background: #3b82f6;
}

.python-btn-clear {
  background: #6b7280;
  color: white;
}

.python-btn-clear:hover:not(:disabled) {
  background: #4b5563;
}

.python-btn-reset {
  background: #ef4444;
  color: white;
}

.python-btn-reset:hover:not(:disabled) {
  background: #dc2626;
}

.python-btn-copy {
  background: #8b5cf6;
  color: white;
  margin-left: auto;
}

.python-btn-copy:hover:not(:disabled) {
  background: #7c3aed;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

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

/* Instructions panel */
.python-instructions-panel {
  padding: 1rem 1.5rem;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}

.python-instructions-panel h4 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.75rem 0;
  color: #e5e7eb;
  font-size: 0.9375rem;
  font-weight: 600;
}

.python-instructions-panel h4 svg {
  width: 1rem;
  height: 1rem;
  color: #fbbf24;
}

.python-instructions-panel .instructions-content {
  color: #9ca3af;
  font-size: 0.875rem;
  line-height: 1.6;
}

.python-instructions-panel .instructions-content code {
  background: #1e1e1e;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: 'Fira Code', monospace;
  color: #f97316;
}

/* Pyodide loading state */
.pyodide-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(30, 30, 30, 0.95);
  z-index: 10;
}

.pyodide-loading-overlay .loading-text {
  margin-top: 1rem;
  color: #9ca3af;
  font-size: 0.875rem;
}

.pyodide-loading-overlay .loading-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-radius: 50%;
  border-top-color: #3b82f6;
  animation: spin 1s ease-in-out infinite;
}

/* Status indicator */
.python-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #9ca3af;
}

.python-status .status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #6b7280;
}

.python-status.ready .status-dot {
  background: #22c55e;
}

.python-status.loading .status-dot {
  background: #3b82f6;
  animation: pulse 1.5s ease-in-out infinite;
}

.python-status.error .status-dot {
  background: #ef4444;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Keyboard shortcut hint */
.keyboard-hint {
  display: none;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: #6b7280;
}

@media (min-width: 768px) {
  .keyboard-hint {
    display: flex;
  }
}

.keyboard-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.125rem 0.375rem;
  background: #374151;
  border: 1px solid #4b5563;
  border-radius: 0.25rem;
  font-family: inherit;
  font-size: 0.6875rem;
  color: #d1d5db;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .python-exercise-header {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }
  
  .python-exercise-actions {
    flex-wrap: wrap;
  }
  
  .python-btn {
    flex: 1;
    justify-content: center;
    min-width: 120px;
  }
  
  .python-btn-copy {
    margin-left: 0;
  }
}

/* Monaco Editor overrides */
.python-editor-container .monaco-editor {
  padding-top: 0.5rem;
}

.python-editor-container .monaco-editor .margin {
  background: #1e1e1e !important;
}

/* Collapsible exercise */
.python-exercise-container details summary {
  cursor: pointer;
  list-style: none;
}

.python-exercise-container details summary::-webkit-details-marker {
  display: none;
}

.python-exercise-container details[open] .chevron-icon {
  transform: rotate(180deg);
}

.python-exercise-container .chevron-icon {
  transition: transform 0.2s;
}

/* Expected output comparison */
.expected-output {
  margin-top: 1rem;
  padding: 1rem;
  background: #252526;
  border-radius: 0.5rem;
  border-left: 3px solid #3b82f6;
}

.expected-output-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: #9ca3af;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.expected-output-content {
  font-family: 'Fira Code', monospace;
  font-size: 0.875rem;
  color: #60a5fa;
}

/* Success/failure feedback */
.exercise-feedback {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.exercise-feedback.success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #4ade80;
}

.exercise-feedback.failure {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.exercise-feedback svg {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

/* Fullscreen mode */
.python-exercise-container.fullscreen-mode {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  margin: 0;
  border: none;
  border-radius: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.python-exercise-container.fullscreen-mode .python-exercise-split {
  flex: 1;
  min-height: 0;
  height: auto;
}

.python-exercise-container.fullscreen-mode .python-editor-panel,
.python-exercise-container.fullscreen-mode .python-output-panel {
  flex: 1;
  min-height: 0;
}

.python-exercise-container.fullscreen-mode .python-editor-container {
  flex: 1;
  min-height: 0;
  height: auto;
}

.python-exercise-container.fullscreen-mode .python-output-content {
  max-height: none;
  flex: 1;
}

/* Ensure Monaco editor fills fullscreen container properly */
.python-exercise-container.fullscreen-mode .monaco-editor {
  height: 100% !important;
}
