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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    transition: all 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.2rem;
    opacity: 0.9;
}

.main-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.controls-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 25px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    height: fit-content;
    overflow-y: auto;
    max-height: 80vh;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
}

.control-group small {
    color: #6b7280;
    font-style: italic;
}

.primary-btn, .secondary-btn, .burst-btn, .zoom-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-right: 10px;
    margin-bottom: 10px;
}

.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.secondary-btn {
    background: #e2e8f0;
    color: #4a5568;
}

.secondary-btn:hover {
    background: #cbd5e0;
    transform: translateY(-2px);
}

.burst-btn {
    background: #f59e0b;
    color: white;
    padding: 8px 16px;
    font-size: 0.9rem;
}

.burst-btn:hover {
    background: #d97706;
}

.zoom-btn {
    background: #6366f1;
    color: white;
    padding: 8px 12px;
    font-size: 0.9rem;
    min-width: 40px;
}

.zoom-btn:hover {
    background: #4f46e5;
}

select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    font-size: 1rem;
}

input[type="range"] {
    width: 100%;
    margin: 10px 0;
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.2);
}

.stats {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
}

.stats div {
    margin-bottom: 5px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
}

.panel {
    margin-top: 20px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.panel summary {
    padding: 15px;
    background: #f7fafc;
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}

.panel-content {
    padding: 15px;
    border-top: 1px solid #e2e8f0;
}

.tutorial-content h4 {
    color: #4a5568;
    margin-bottom: 10px;
}

.tutorial-content ol,
.tutorial-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.tutorial-content li {
    margin-bottom: 5px;
}

.canvas-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.canvas-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#zoomLevel {
    font-weight: 600;
    color: #4a5568;
}

.minimap-container {
    position: relative;
    border: 2px solid #6366f1;
    border-radius: 8px;
    overflow: hidden;
}

#minimap {
    display: block;
    background: #f8fafc;
}

.minimap-viewport {
    position: absolute;
    border: 2px solid #ef4444;
    pointer-events: none;
}

.canvas-container {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    overflow: hidden;
}

#canvas, #gridCanvas, #trailCanvas {
    position: absolute;
    top: 20px;
    left: 20px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: grab;
}

#canvas:active {
    cursor: grabbing;
}

#gridCanvas {
    z-index: 1;
    pointer-events: none;
}

#trailCanvas {
    z-index: 2;
    pointer-events: none;
}

#canvas {
    z-index: 3;
}

.canvas-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 30px;
    border-radius: 10px;
    text-align: center;
    font-size: 1.1rem;
    pointer-events: none;
    opacity: 0.9;
    z-index: 10;
}

.analysis-stats {
    margin: 15px 0;
}

.analysis-stats div {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-weight: 600;
}

.formula-display {
    background: #f0f9ff;
    padding: 10px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    text-align: center;
    border: 1px solid #bae6fd;
}

#convergenceChart {
    width: 100%;
    height: 100px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
}

footer {
    text-align: center;
    color: white;
    opacity: 0.9;
    margin-top: 30px;
}

footer a {
    color: #fbbf24;
    text-decoration: none;
    font-weight: 600;
}

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

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .controls-panel {
        padding: 15px;
        max-height: none;
    }
    
    .canvas-controls {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .zoom-controls {
        justify-content: center;
    }
    
    .minimap-container {
        align-self: center;
    }
    
    .primary-btn, .secondary-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .burst-controls {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .burst-btn {
        flex: 1;
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .canvas-container {
        padding: 10px;
    }
    
    #canvas, #gridCanvas, #trailCanvas {
        top: 10px;
        left: 10px;
    }
}

/* Animations */
@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px rgba(102, 126, 234, 0.5); }
    50% { box-shadow: 0 0 20px rgba(102, 126, 234, 0.8); }
}

.primary-btn:active {
    animation: glow 0.3s ease-in-out;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .controls-panel {
        background: rgba(31, 41, 55, 0.95);
        color: #f3f4f6;
    }
    
    .control-group label {
        color: #d1d5db;
    }
    
    .control-group small {
        color: #9ca3af;
    }
    
    .stats {
        background: #374151;
        color: #f3f4f6;
    }
    
    .panel summary {
        background: #374151;
        color: #f3f4f6;
    }
    
    .panel-content {
        background: #1f2937;
        color: #f3f4f6;
        border-top-color: #4b5563;
    }
    
    .formula-display {
        background: #1e293b;
        color: #f1f5f9;
        border-color: #475569;
    }
    
    .canvas-container {
        background: rgba(31, 41, 55, 0.95);
    }
}