* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(45deg, #ED225D, #2D7BB6, #F5A623);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auto-run-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
}

.auto-run-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 0, 0, 0.1);
    border-radius: 20px;
    border: 2px solid rgba(255, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.auto-run-indicator.active {
    background: rgba(76, 175, 80, 0.1);
    border-color: rgba(76, 175, 80, 0.5);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f44336;
    transition: background 0.3s ease;
}

.auto-run-indicator.active .status-dot {
    background: #4CAF50;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

.status-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: #f44336;
}

.auto-run-indicator.active .status-text {
    color: #4CAF50;
}

.toggle-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: #f5f5f5;
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
}

.nav-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-tab:hover {
    background: rgba(0, 0, 0, 0.05);
}

.nav-tab.active {
    background: #ED225D;
    color: white;
}

.quick-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f5f5f5;
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    min-height: calc(100vh - 140px);
}

.split-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
    height: 500px;
}

/* Left Panel - Code Editor */
.left-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.editor-header {
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    width: 100%;
}

#template-dropdown {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
}

.execution-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.debounce-timer {
    width: 40px;
    height: 4px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.debounce-timer.running::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: linear-gradient(45deg, #4CAF50, #2196F3);
    animation: debounce-fill 0.8s ease-out;
}

@keyframes debounce-fill {
    from { width: 0%; }
    to { width: 100%; }
}

.execution-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: #666;
    min-width: 80px;
}

.editor-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

.code-editor {
    height: 100%;
}

.typing-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, #2196F3, transparent);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.typing-indicator.active {
    transform: translateX(100%);
    animation: typing-pulse 1.5s infinite;
}

@keyframes typing-pulse {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

.error-display {
    background: linear-gradient(45deg, #f8d7da, #f5c6cb);
    border-top: 1px solid #f5c6cb;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideDown 0.3s ease-out;
}

.error-display.hidden {
    display: none;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.error-content {
    flex: 1;
}

.error-title {
    font-weight: 600;
    color: #721c24;
    margin-bottom: 0.25rem;
}

.error-message {
    color: #721c24;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
}

/* Right Panel - Canvas */
.right-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    position: relative;
}

.canvas-container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    position: relative;
}

.canvas-feedback {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 0.5rem 1rem;
    background: rgba(76, 175, 80, 0.9);
    color: white;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 10;
}

.canvas-feedback.show {
    opacity: 1;
    transform: translateY(0);
}

#p5-canvas-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.execution-glow {
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.5) !important;
}

.execution-flash {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(76, 175, 80, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.execution-flash.success {
    opacity: 1;
    animation: flash 0.3s ease-out;
}

@keyframes flash {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Tutorial Overlay */
.tutorial-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.tutorial-overlay.hidden {
    display: none;
}

.tutorial-bubble {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 450px;
    margin: 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: bubbleIn 0.5s ease-out;
}

@keyframes bubbleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.tutorial-content h3 {
    color: #ED225D;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.tutorial-content p {
    color: #666;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.tutorial-hint {
    background: linear-gradient(45deg, #FFF3CD, #FCF8E3);
    border: 1px solid #FFEAA7;
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 2rem;
    font-size: 0.9rem;
    color: #856404;
}

.tutorial-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tutorial-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ED225D;
    background: white;
    color: #ED225D;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.tutorial-btn:hover:not(:disabled) {
    background: #ED225D;
    color: white;
}

.tutorial-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#step-counter {
    font-weight: 600;
    color: #666;
}

/* Bottom Panel */
.bottom-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    min-height: 300px;
}

.panel-content {
    display: none;
}

.panel-content.active {
    display: block;
}

/* Tutorial Content */
.lesson-controls {
    display: flex;
    gap: 2rem;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

#lesson-selector {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    min-width: 300px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #eee;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(45deg, #ED225D, #F5A623);
    width: 0%;
    transition: width 0.3s ease;
}

.auto-run-badge {
    background: linear-gradient(45deg, #4CAF50, #2196F3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    animation: pulse 2s infinite;
}

.feature-highlight {
    margin: 1.5rem 0;
    padding: 1.5rem;
    background: linear-gradient(45deg, #f8f9fa, #e9ecef);
    border-radius: 8px;
    border-left: 4px solid #4CAF50;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.feature-item:last-child {
    margin-bottom: 0;
}

.feature-icon {
    font-size: 1.2rem;
}

.start-tutorial-btn {
    padding: 1rem 2rem;
    background: linear-gradient(45deg, #ED225D, #2D7BB6);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 1rem;
}

.start-tutorial-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(237, 34, 93, 0.3);
}

/* Playground Tools */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.tool-btn {
    padding: 1rem;
    border: 2px solid #ED225D;
    background: white;
    color: #ED225D;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #ED225D;
    color: white;
    transform: translateY(-2px);
}

/* Examples */
.examples-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.example-filters {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.4rem 0.8rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.filter-btn.active {
    background: #2D7BB6;
    color: white;
    border-color: #2D7BB6;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.example-card {
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
    background: white;
}

.example-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.example-preview {
    height: 120px;
    background: linear-gradient(45deg, #f8f9fa, #e9ecef);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.auto-run-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(45deg, #4CAF50, #2196F3);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.example-info {
    padding: 1rem;
}

.example-info h4 {
    margin-bottom: 0.5rem;
    color: #333;
}

.example-tags {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tag {
    padding: 0.2rem 0.5rem;
    background: #f0f0f0;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #666;
}

.load-example-btn {
    width: 100%;
    padding: 0.6rem;
    background: #F5A623;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.load-example-btn:hover {
    background: #e8950f;
    transform: translateY(-1px);
}

/* Reference */
.reference-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.function-lookup {
    position: relative;
}

.function-lookup h4 {
    margin-bottom: 0.5rem;
    color: #333;
}

#function-search {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
}

.function-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.function-result {
    padding: 0.6rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background 0.2s;
}

.function-result:hover {
    background: #f8f9fa;
}

.color-palette {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.color-palette h4 {
    margin-bottom: 0.5rem;
    color: #333;
}

#color-picker {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.coordinate-helper h4 {
    margin-bottom: 1rem;
    color: #333;
}

.coordinate-helper label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-bottom: 0.5rem;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 2rem;
}

.footer a {
    color: #F5A623;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
        padding: 0 1rem;
    }

    .logo {
        flex-direction: column;
        text-align: center;
    }

    .auto-run-status {
        margin-left: 0;
    }

    .nav-tabs {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .split-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .left-panel, .right-panel {
        height: 400px;
    }

    .main-content {
        padding: 1rem;
    }

    .lesson-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .examples-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .reference-sections {
        grid-template-columns: 1fr;
    }

    .examples-grid {
        grid-template-columns: 1fr;
    }
}

/* Animations for auto-run feedback */
@keyframes successGlow {
    0% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); }
    50% { box-shadow: 0 0 30px rgba(76, 175, 80, 0.6); }
    100% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); }
}

@keyframes errorGlow {
    0% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); }
    50% { box-shadow: 0 0 30px rgba(244, 67, 54, 0.6); }
    100% { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .nav-tab.active {
        background: #000;
        color: #fff;
    }
    
    .action-btn:hover {
        background: #000;
        color: #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .typing-indicator, .auto-run-badge, .execution-flash {
        animation: none !important;
    }
    
    .debounce-timer.running::after {
        animation: none !important;
    }
}