* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    touch-action: manipulation;
}

h1 {
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 30px;
    font-size: 2.5em;
}

.container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    gap: 30px;
    max-width: 1400px;
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.canvas-container {
    border: 3px solid #333;
    border-radius: 10px;
    background: #f0f0f0;
    padding: 10px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

canvas {
    display: block;
    cursor: default;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    touch-action: none;
}

.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

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

.btn-clear {
    background: #ff4757;
    color: white;
}

.btn-clear:hover {
    background: #ff3838;
}

.btn-export {
    background: #2ecc71;
    color: white;
}

.btn-export:hover {
    background: #27ae60;
}

.btn-save {
    background: #3498db;
    color: white;
}

.btn-save:hover {
    background: #2980b9;
}

.btn-load {
    background: #9b59b6;
    color: white;
}

.btn-load:hover {
    background: #8e44ad;
}

.btn-tool {
    background: #f0f0f0;
    color: #333;
    border: 2px solid #ccc;
}

.btn-tool:hover {
    background: #e0e0e0;
}

.btn-tool.selected {
    background: #667eea;
    color: white;
    border-color: #4a5cb8;
}

.eraser-btn.selected {
    background: #e74c3c;
    color: white;
    border-width: 4px;
}

.btn-undo {
    background: #ecf0f1;
    color: #333;
    border: 2px solid #bdc3c7;
}

.btn-undo:hover:not(:disabled) {
    background: #d5dbdb;
}

.btn-undo:disabled {
    cursor: not-allowed;
}

.btn-melt {
    background: #f39c12;
    color: white;
}

.btn-melt:hover {
    background: #e67e22;
}

.btn-melt.selected {
    background: #e74c3c;
    border: 2px solid #c0392b;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 250px;
}

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

.section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.2em;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.color-btn {
    width: 50px;
    height: 50px;
    min-width: 44px;
    min-height: 44px;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    touch-action: manipulation;
}

.color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.color-btn.selected {
    border-color: #000;
    border-width: 4px;
    transform: scale(1.15);
}

.eraser-btn {
    width: 100%;
    padding: 15px;
    background: white;
    border: 3px solid #e74c3c;
    color: #e74c3c;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.eraser-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(45deg,
            transparent,
            transparent 10px,
            rgba(231, 76, 60, 0.1) 10px,
            rgba(231, 76, 60, 0.1) 20px);
}

.eraser-btn:hover {
    background: #e74c3c;
    color: white;
}

.eraser-btn.selected {
    background: #e74c3c;
    color: white;
    border-width: 4px;
}

.current-tool {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    border: 2px solid #ddd;
}

.tool-indicator {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #333;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.tool-indicator.eraser {
    background: repeating-linear-gradient(45deg,
            #e74c3c,
            #e74c3c 10px,
            white 10px,
            white 20px);
}

.tool-label {
    font-weight: bold;
    color: #555;
}

@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }

    .right-panel {
        min-width: 100%;
    }
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

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

.modal {
    background: white;
    border-radius: 12px;
    width: 380px;
    max-height: 80vh;
    overflow: auto;
    padding: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    margin-bottom: 15px;
}

.modal input {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    margin-bottom: 15px;
}

.project-item {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
}

.project-item.selected {
    background: #3498db;
    color: white;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}

.actions-grid button {
    width: 100%;
}