* {
    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;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.header-title {
    text-align: left;
}

header h1 {
    font-size: 2em;
    margin-bottom: 8px;
}

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

.language-switch {
    display: flex;
    gap: 5px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 4px;
}

.lang-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lang-btn.active {
    background: white;
    color: #667eea;
}

.upload-section {
    padding: 40px;
}

.upload-area {
    border: 3px dashed #667eea;
    border-radius: 12px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9ff;
}

.upload-area:hover {
    border-color: #764ba2;
    background: #f0f2ff;
}

.upload-area.dragover {
    border-color: #764ba2;
    background: #e8ebff;
    transform: scale(1.01);
}

.upload-icon {
    font-size: 4em;
    margin-bottom: 16px;
}

.upload-area p {
    font-size: 1.2em;
    color: #555;
    margin-bottom: 8px;
}

.upload-hint {
    font-size: 0.9em;
    color: #888;
}

.workspace {
    padding: 30px;
}

.preview-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.preview-container.has-perler {
    grid-template-columns: 1fr 1fr 1fr;
}

.preview-panel {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px;
}

.preview-panel h3 {
    margin-bottom: 16px;
    color: #333;
    font-size: 1.1em;
}

.canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #e9ecef;
    border-radius: 8px;
    overflow: hidden;
    min-height: 200px;
}

canvas {
    max-width: 100%;
    height: auto;
    display: block;
    image-rendering: pixelated;
}

.size-info {
    margin-top: 12px;
    text-align: center;
    color: #666;
    font-size: 0.9em;
}

.controls {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 25px;
}

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

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: #333;
}

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

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    cursor: pointer;
    border: none;
}

.size-inputs {
    display: flex;
    gap: 20px;
}

.size-inputs > div {
    flex: 1;
}

.size-inputs label {
    display: inline-block;
    margin-bottom: 6px;
    font-weight: normal;
}

.size-inputs input[type="number"] {
    width: 120px;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    margin-right: 6px;
    transition: border-color 0.3s;
}

.size-inputs input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

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

.preset-btn {
    padding: 10px 20px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.3s;
}

.preset-btn:hover {
    background: #667eea;
    color: white;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #667eea;
}

.action-buttons {
    display: flex;
    gap: 15px;
    margin-top: 30px;
    padding-top: 25px;
    border-top: 2px solid #e9ecef;
}

.btn {
    flex: 1;
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

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

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

.btn-secondary {
    background: #e9ecef;
    color: #495057;
}

.btn-secondary:hover {
    background: #dee2e6;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #bb2d3b;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
}

select {
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

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

#perlerOptions {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    border: 2px dashed #667eea;
}

#perlerContent {
    display: flex;
    flex-direction: column;
}

#perlerChartArea {
    display: flex;
    flex-direction: column;
}

.perler-chart-wrapper {
    display: flex;
    flex-direction: column;
}

#colorLegendArea {
    display: flex;
    justify-content: center;
}

#colorLegendArea.horizontal {
    flex-direction: row;
    justify-content: flex-start;
}

#colorLegend {
    display: flex;
    justify-content: center;
}

#colorLegend.horizontal {
    justify-content: flex-start;
}

#colorLegend canvas {
    max-width: none;
}

@media (max-width: 768px) {
    .perler-layout-horizontal {
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .preview-container,
    .preview-container.has-perler {
        grid-template-columns: 1fr;
    }

    .size-inputs {
        flex-direction: column;
    }

    .action-buttons {
        flex-direction: column;
    }
}
