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

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

.container {
    display: flex;
    min-height: 100vh;
    gap: 2rem;
    padding: 2rem;
}

.controls {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 16px;
    min-width: 300px;
    max-width: 350px;
    height: fit-content;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    max-height: calc(100vh - 4rem);
}

.controls h1 {
    margin-bottom: 2rem;
    color: #5a67d8;
    text-align: center;
    font-size: 1.8rem;
    font-weight: 600;
}

.control-group {
    margin-bottom: 1.5rem;
}

.control-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #4a5568;
}

/* File Input */
.file-input {
    width: 100%;
    padding: 0.5rem;
    border: 2px dashed #5a67d8;
    border-radius: 8px;
    background: #f7fafc;
    cursor: pointer;
    font-size: 0.9rem;
}

.file-input:hover {
    border-color: #4c51bf;
    background: #edf2f7;
}

/* Range Inputs */
input[type="range"] {
    width: 100%;
    margin-bottom: 0.5rem;
    -webkit-appearance: none;
    background: #e2e8f0;
    border-radius: 5px;
    height: 6px;
}

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

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

/* Tool Buttons */
.tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

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

.tool-btn:hover {
    border-color: #5a67d8;
    background: #f7fafc;
}

.tool-btn.active {
    background: #5a67d8;
    color: white;
    border-color: #5a67d8;
}

/* Regular Buttons */
button {
    width: 100%;
    padding: 0.75rem;
    margin-top: 0.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover {
    transform: translateY(-2px);
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
}

.action-buttons button {
    margin-top: 0;
    background: #5a67d8;
    color: white;
}

.action-buttons button:hover {
    background: #4c51bf;
}

.warning-btn {
    background: #f56565 !important;
    color: white !important;
}

.warning-btn:hover {
    background: #e53e3e !important;
}

/* Export Buttons */
.export-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.export-buttons button {
    margin-top: 0;
}

.export-btn {
    background: #38b2ac;
    color: white;
}

.export-btn:hover {
    background: #319795;
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
    border-color: #5a67d8;
}

.color-swatch.selected {
    border-color: #5a67d8;
    border-width: 3px;
}

.color-swatch.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#coloring-canvas {
    border-radius: 16px;
    background: white;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
    max-width: 100%;
    max-height: calc(100vh - 4rem);
    cursor: crosshair;
}

/* Instructions Overlay */
.instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    text-align: left;
    pointer-events: none;
}

.instructions h3 {
    color: #5a67d8;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.instructions ol {
    margin-left: 1.5rem;
    color: #4a5568;
    line-height: 1.8;
}

.instructions li {
    margin-bottom: 0.5rem;
}

/* Hide instructions when canvas has content */
#coloring-canvas:not([width="800"]) ~ .instructions {
    display: none;
}

/* Value Displays */
span[id$="-value"] {
    display: inline-block;
    width: 3rem;
    text-align: right;
    font-weight: 600;
    color: #5a67d8;
}

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

    .controls {
        min-width: auto;
        max-width: none;
        max-height: none;
    }

    .canvas-container {
        min-height: 400px;
    }

    .tool-buttons {
        grid-template-columns: 1fr 1fr;
    }

    .instructions {
        max-width: calc(100% - 2rem);
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .action-buttons {
        grid-template-columns: 1fr;
    }

    .tool-buttons {
        grid-template-columns: 1fr;
    }
}

/* Scrollbar Styling */
.controls::-webkit-scrollbar {
    width: 8px;
}

.controls::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.controls::-webkit-scrollbar-thumb {
    background: #5a67d8;
    border-radius: 10px;
}

.controls::-webkit-scrollbar-thumb:hover {
    background: #4c51bf;
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

.loading-content {
    background: white;
    padding: 3rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    min-width: 300px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #5a67d8;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-message {
    font-size: 1.1rem;
    font-weight: 500;
    color: #4a5568;
    margin-bottom: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #5a67d8, #764ba2);
    width: 0%;
    transition: width 0.3s ease;
}
