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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
}

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

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

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: #2c3e50;
}

header p {
    font-size: 1.1rem;
    color: #666;
}

main {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr;
}

section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.camera-section {
    grid-column: 1 / -1;
}

.camera-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

#webcam {
    max-width: 400px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    background: #000;
    aspect-ratio: 4/3;
}

#outputCanvas {
    max-width: 400px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    background: #000;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.camera-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.pattern-section {
    display: grid;
    gap: 20px;
}

.pattern-upload h2 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.3rem;
}

input[type="file"] {
    width: 100%;
    padding: 10px;
    border: 2px dashed #ddd;
    border-radius: 4px;
    margin-bottom: 15px;
    cursor: pointer;
    transition: border-color 0.3s;
}

input[type="file"]:hover {
    border-color: #3498db;
}

.pattern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.pattern-item {
    aspect-ratio: 1;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid #ddd;
    transition: border-color 0.3s;
}

.pattern-item:hover {
    border-color: #3498db;
}

.pattern-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.controls-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    align-items: center;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
}

select,
input[type="range"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

input[type="range"] {
    appearance: none;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: #3498db;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #2980b9;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #3498db;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.info-section {
    background: #34495e;
    color: white;
}

.performance-info {
    display: flex;
    gap: 30px;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
}

button {
    background: #3498db;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

button:hover:not(:disabled) {
    background: #2980b9;
    transform: translateY(-1px);
}

button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

button:active:not(:disabled) {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .camera-container {
        flex-direction: column;
        align-items: center;
    }
    
    #webcam,
    #outputCanvas {
        max-width: 100%;
    }
    
    .controls-section {
        grid-template-columns: 1fr;
    }
    
    .performance-info {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .camera-controls {
        flex-direction: column;
        align-items: center;
    }
    
    button {
        width: 100%;
        max-width: 200px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    section {
        padding: 15px;
    }
    
    .pattern-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    }
}

.steps-container {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.steps-preview {
    display: flex;
    gap: 2px;
    height: 30px;
    flex: 1;
}

.random-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0 12px;
    height: 30px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    white-space: nowrap;
}

.random-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.random-btn:active {
    transform: scale(0.95);
}

.step-swatch {
    flex: 1;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    position: relative;
}

.step-swatch:hover {
    transform: scale(1.05);
    border-color: #3498db;
}

.step-swatch.selected {
    border-color: #e74c3c;
    transform: scale(1.1);
}

.color-editor {
    background: #2c3e50;
    color: white;
    border-radius: 8px;
    margin-top: 20px;
}

.color-editor h3 {
    text-align: center;
    margin-bottom: 20px;
    color: #ecf0f1;
}

.color-controls {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 20px;
    align-items: start;
}

.step-type-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.type-selector {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
}

.type-selector input[type="radio"] {
    margin-right: 5px;
}

.type-selector label {
    color: #ecf0f1;
    font-weight: 500;
    cursor: pointer;
}

.image-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.image-controls input[type="file"] {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 8px;
}

.step-image-preview {
    width: 100px;
    height: 100px;
    border: 2px solid #34495e;
    border-radius: 4px;
    background: #2c3e50;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.step-image-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.color-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.color-swatch {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    border: 3px solid #34495e;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.hsb-controls {
    display: grid;
    gap: 15px;
}

.hsb-controls .control-group {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 10px;
    align-items: center;
}

.hsb-controls label {
    color: #bdc3c7;
    font-weight: 500;
}

.hsb-controls input[type="range"] {
    background: #34495e;
}

.hsb-controls input[type="range"]::-webkit-slider-thumb {
    background: #e74c3c;
}

.hsb-controls input[type="range"]::-moz-range-thumb {
    background: #e74c3c;
}

.color-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.color-actions button {
    background: #34495e;
    border: 1px solid #7f8c8d;
}

.color-actions button:hover {
    background: #4a5f7a;
}

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

.effects-section h2 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.effects-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.effects-section .control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.effects-section label {
    color: #f8f9fa;
    font-weight: 600;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.effects-section input[type="range"] {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.effects-section input[type="range"]::-webkit-slider-thumb {
    background: #ff6b6b;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.effects-section input[type="range"]::-moz-range-thumb {
    background: #ff6b6b;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.effects-section span {
    color: #f8f9fa;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}