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

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

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

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

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

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

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

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
}

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

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

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

.primary-btn, .secondary-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;
    min-height: 44px; /* Touch-friendly */
}

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

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

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

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

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

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

select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 1rem;
    cursor: pointer;
    min-height: 44px; /* Touch-friendly */
}

select:focus {
    border-color: #667eea;
    outline: none;
}

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

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.speed-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 5px;
}

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

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

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

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

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

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

.help-content {
    padding: 15px;
    border-top: 2px solid #e2e8f0;
    font-size: 0.9rem;
}

.help-content p {
    margin-bottom: 10px;
}

.help-content ol {
    margin: 10px 0 10px 20px;
}

.help-content li {
    margin-bottom: 4px;
}

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

.canvas-container {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
}

#canvas {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    cursor: grab;
    touch-action: none;
    max-width: 100%;
    height: auto;
}

#canvas:active {
    cursor: grabbing;
}

.canvas-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 20px 25px;
    border-radius: 10px;
    text-align: center;
    font-size: 1rem;
    pointer-events: none;
    opacity: 0.95;
    z-index: 10;
    max-width: 80%;
}

.performance-info {
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #4a5568;
    text-align: center;
    font-family: 'Courier New', monospace;
}

footer {
    text-align: center;
    color: white;
    opacity: 0.9;
    margin-top: 20px;
    font-size: 0.9rem;
}

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

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

footer p {
    margin-bottom: 5px;
}

/* High contrast mode for better visibility */
@media (prefers-contrast: high) {
    .controls-panel {
        background: rgba(255, 255, 255, 1);
        border: 3px solid #000;
    }
    
    .canvas-container {
        background: rgba(255, 255, 255, 1);
        border: 3px solid #000;
    }
    
    #canvas {
        border: 3px solid #000;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .controls-panel {
        background: rgba(31, 41, 55, 0.95);
        color: #f3f4f6;
    }
    
    .control-group label {
        color: #d1d5db;
    }
    
    .stats {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    
    .help-panel summary {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    
    .help-content {
        background: #1f2937;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    
    .canvas-container {
        background: rgba(31, 41, 55, 0.95);
    }
    
    .performance-info {
        background: rgba(31, 41, 55, 0.9);
        color: #d1d5db;
    }
}

/* Ensure touch targets are large enough */
@media (max-width: 480px) {
    .primary-btn, .secondary-btn {
        width: 100%;
        margin-right: 0;
        font-size: 1.1rem;
        padding: 14px 20px;
    }
    
    .canvas-container {
        padding: 15px;
    }
    
    .controls-panel {
        padding: 15px;
    }
    
    input[type="range"]::-webkit-slider-thumb,
    input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }
}

/* Animation for better feedback */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

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

/* Accessibility improvements */
:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

button:focus,
select:focus,
input:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Loading state */
.canvas-overlay.loading {
    animation: pulse 2s infinite;
}