/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f5f7fa;
    color: #333;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header */
.challenge-header {
    background: white;
    border-bottom: 2px solid #e1e8ed;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-section {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
    background: #f8f9fa;
    border-color: #0080ff;
    color: #0080ff;
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-btn svg {
    width: 16px;
    height: 16px;
}

#challengeTitle {
    font-size: 1.5rem;
    color: #0080ff;
}

.progress-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

#progressText {
    font-size: 0.875rem;
    color: #666;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: #e1e8ed;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0080ff 0%, #00c0ff 100%);
    transition: width 0.3s ease;
}

/* Main container */
.challenge-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Top section - Image and Description */
.challenge-info-section {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    background: white;
    padding: 1.25rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: relative;
}

.challenge-image-container {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.challenge-image {
    width: 230px;
    height: 230px;
    object-fit: contain;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    background: white;
    padding: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.challenge-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.challenge-description-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.challenge-description-container h2 {
    color: #0080ff;
    margin-bottom: 0.75rem;
    font-size: 1.5rem;
}

.challenge-description-container p {
    font-size: 1.05rem;
    line-height: 1.6;
    color: #555;
    margin-bottom: 1rem;
}

/* Completion checkbox - positioned in upper right */
.completion-corner {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
}

.completion-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    background: rgba(248, 249, 250, 0.9);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #ddd;
    transition: all 0.2s;
}

.completion-checkbox:hover {
    background: #f8f9fa;
    border-color: #0080ff;
}

.completion-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 0.5rem;
    cursor: pointer;
}

.completion-checkbox span {
    font-size: 0.875rem;
    font-weight: 500;
    color: #666;
}

.completion-checkbox input[type="checkbox"]:checked + span {
    color: #28a745;
}

/* Hints section */
.hints-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
}

.hint-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: #0080ff;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    padding: 0.5rem;
    width: 100%;
    text-align: left;
}

.hint-toggle:hover {
    background: rgba(0, 128, 255, 0.1);
    border-radius: 4px;
}

.hint-arrow {
    display: inline-block;
    transition: transform 0.2s;
}

.hint-content {
    margin-top: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 4px;
}

.hint-content ol {
    margin-left: 1.5rem;
}

.hint-content li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

/* Control buttons - Hidden, using control-buttons-output instead */
.control-buttons {
    display: none;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: #0080ff;
    color: white;
}

.btn-primary:hover {
    background: #0066cc;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 128, 255, 0.3);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-warning {
    background: #ffc107;
    color: #333;
}

.btn-warning:hover {
    background: #e0a800;
}

/* Bottom section - Editor and Output */
.coding-section {
    display: flex;
    gap: 1.5rem;
    min-height: 600px;
    height: auto;
}

.editor-panel {
    flex: 0 0 33.333%;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.output-panel {
    flex: 0 0 calc(66.666% - 1.5rem);
    min-height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.panel-header {
    background: #2d3748;
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
}

/* Header controls for output panel */
.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.header-btn svg {
    width: 14px;
    height: 14px;
}

.header-btn-primary {
    background: #48bb78;
    border-color: #48bb78;
}

.header-btn-primary:hover {
    background: #38a169;
    border-color: #38a169;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.3);
    margin: 0 0.25rem;
}

.editor-controls {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* CodeMirror editor */
.CodeMirror {
    flex: 1;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    height: 100%;
}

.CodeMirror .error-line {
    background: rgba(255, 0, 0, 0.2);
}

/* Output panel */
.canvas-wrapper {
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    overflow: visible;
    flex: 1;
    min-height: 0;
}

/* Control buttons in output panel - No longer used */
.control-buttons-output {
    display: none;
}

.canvas-container {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    background: white;
    margin: 1rem;
    margin-bottom: 0;
    border-radius: 8px 8px 0 0;
}

.turtle-canvas {
    width: 400px;
    height: 400px;
    border: 2px solid #e1e8ed;
    background: white;
    position: relative;
}

/* Console */
.console {
    flex: 0 0 auto;
    height: auto;
    background: #1a202c;
    margin: 0 1rem 1rem 1rem;
    border-radius: 0 0 8px 8px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.console.expanded {
    /* Show full console when expanded */
}

.console:not(.expanded) #consoleOutput {
    height: 0;
    overflow: hidden;
}

.console.expanded #consoleOutput {
    height: 200px;
    overflow-y: auto;
}

.console-header {
    padding: 0.5rem 1rem;
    background: rgba(255,255,255,0.05);
    color: #48bb78;
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.console-header:hover {
    background: rgba(255,255,255,0.08);
}

.console-toggle {
    background: none;
    border: none;
    color: #48bb78;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.console-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.console-toggle svg {
    transition: transform 0.3s ease;
}

.console.expanded .console-toggle svg {
    transform: rotate(180deg);
}

#consoleOutput {
    padding: 0.75rem 1rem;
    color: #48bb78;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: height 0.3s ease;
}

#consoleOutput::-webkit-scrollbar {
    width: 8px;
}

#consoleOutput::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
}

#consoleOutput::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e1e8ed;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: #0080ff;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f8f9fa;
}

.modal-body {
    padding: 1.5rem;
}

.share-link-container {
    display: flex;
    gap: 0.75rem;
    margin: 1rem 0;
}

.share-link-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.875rem;
}

.share-note {
    margin-top: 1rem;
    font-size: 0.875rem;
    color: #666;
    font-style: italic;
}

.solution-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.solution-code {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #2d3748;
    color: #48bb78;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.875rem;
    overflow-x: auto;
}

/* Image fullscreen modal */
.image-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    cursor: pointer;
}

.image-modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    background: white;
    padding: 20px;
    border-radius: 8px;
    cursor: default;
}

.image-modal-close {
    position: absolute;
    top: 2rem;
    right: 2rem;
    color: white;
    font-size: 2.5rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    transition: background 0.2s;
}

.image-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #48bb78;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 3000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: #48bb78;
}

.toast.error {
    background: #ff6b6b;
}

.toast.info {
    background: #0080ff;
}

.toast.warning {
    background: #ffc107;
    color: #333;
}

/* Fullscreen mode */
.fullscreen-mode .coding-section {
    height: calc(100vh - 80px) !important;
    max-width: 100%;
    padding: 1rem;
}

.fullscreen-mode .editor-panel {
    height: calc(100vh - 100px) !important;
}

.fullscreen-mode .output-panel {
    height: calc(100vh - 100px) !important;
}

.fullscreen-mode .canvas-wrapper {
    flex: 1;
}

.fullscreen-mode .canvas-container {
    flex: 1;
    padding: 1rem;
}

.fullscreen-mode .turtle-canvas {
    /* Size will be set dynamically by JavaScript */
    transition: width 0.3s ease, height 0.3s ease;
}

/* Responsive design */
@media (max-width: 1200px) {
    .challenge-image {
        width: 200px;
        height: 200px;
    }
}

@media (max-width: 1024px) {
    .challenge-info-section {
        flex-direction: column;
        align-items: center;
    }

    .challenge-image {
        width: 100%;
        max-width: 250px;
        height: auto;
        aspect-ratio: 1;
    }

    .coding-section {
        flex-direction: column;
        height: auto;
    }

    .editor-panel {
        flex: 1 1 auto;
        min-height: 400px;
    }

    .output-panel {
        flex: 1 1 auto;
        min-height: 500px;
    }

    .turtle-canvas {
        width: 350px;
        height: 350px;
    }
}

@media (max-width: 768px) {
    .challenge-header {
        padding: 0.75rem 1rem;
    }

    #challengeTitle {
        font-size: 1.25rem;
    }

    .progress-section {
        display: none;
    }

    .nav-btn span {
        display: none;
    }

    .nav-btn {
        padding: 0.5rem;
    }

    .challenge-container {
        padding: 1rem;
    }

    .challenge-info-section {
        padding: 1.5rem;
    }

    .control-buttons {
        flex-direction: column;
    }

    .control-buttons .btn {
        width: 100%;
    }

    .coding-section {
        gap: 1rem;
    }

    .turtle-canvas {
        width: 300px;
        height: 300px;
    }
}