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

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

.container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 1200px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

h1 {
    color: #333;
    margin-bottom: 10px;
    text-align: center;
    font-size: 2.5em;
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

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

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

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

.upload-icon {
    font-size: 4em;
    color: #667eea;
    margin-bottom: 15px;
}

.upload-text {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 10px;
}

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

#fileInput {
    display: none;
}

.preview-section {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 30px;
    align-items: start;
}

.preview-section.active {
    display: grid;
}

.preview-box {
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    padding: 20px;
    background: #fafafa;
}

.preview-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 15px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 15px;
    padding: 15px;
    overflow: auto;
}

canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
}

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

button {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    min-width: 120px;
}

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

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

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

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

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.info-box {
    background: #e8f4fd;
    border-left: 4px solid #2196F3;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
}

.info-box p {
    color: #333;
    line-height: 1.6;
    margin-bottom: 5px;
}

.loading {
    display: none;
    text-align: center;
    padding: 20px;
    color: #667eea;
    font-size: 1.2em;
}

.loading.active {
    display: block;
}

.filter-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.resize-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.resize-content {
    max-height: 1000px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 0.3s ease-out;
    display: block;
}

.resize-content.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.filter-title {
    font-size: 1.1em;
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
}

.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-btn {
    flex: 0 0 auto;
    padding: 8px 16px;
    border: 2px solid #667eea;
    border-radius: 20px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
    background: white;
    color: #667eea;
    font-weight: 500;
}

.filter-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
}

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

.resize-control {
    padding: 15px;
    background: #f8f9ff;
    border-radius: 10px;
    margin-bottom: 10px;
}

.filter-control {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9ff;
    border-radius: 10px;
    display: none;
}

.filter-control.active {
    display: block;
}

.filter-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.filter-control-label {
    font-weight: 600;
    color: #333;
    font-size: 0.95em;
}

.filter-control-value {
    font-weight: 700;
    color: #667eea;
    font-size: 1.1em;
}

.filter-slider {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: linear-gradient(to right, #e0e0e0 0%, #667eea 100%);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

#scaleSlider {
    width: 100%;
}

.filter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.filter-slider::-webkit-slider-thumb:hover {
    background: #764ba2;
    transform: scale(1.2);
}

.filter-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
}

.filter-slider::-moz-range-thumb:hover {
    background: #764ba2;
    transform: scale(1.2);
}

.dithering-section {
    background: #f8f9ff;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
}

.dithering-header {
    margin-bottom: 10px;
}

.dithering-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    color: #333;
    font-size: 1.05em;
}

.dithering-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #667eea;
}

.dithering-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    padding-left: 10px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transform: translateY(-4px);
    transition: max-height 0.6s cubic-bezier(0.22, 0.65, 0.2, 1), opacity 0.45s ease-out, transform 0.6s cubic-bezier(0.22, 0.65, 0.2, 1);
}

.dithering-options.active {
    max-height: 240px;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: #555;
    font-size: 0.95em;
    padding: 5px;
    border-radius: 5px;
    transition: background 0.2s;
}

.radio-label:hover {
    background: #e8ebff;
}

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

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 800px;
    max-height: 80vh;
    overflow: auto;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

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

.modal-title {
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    color: #333;
}

.image-focus-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.image-focus-modal.active {
    display: flex;
}

.image-focus-content {
    position: relative;
    width: 90%;
    height: 80%;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.image-focus-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f5f5f5;
    border-top: 1px solid #ddd;
    gap: 15px;
}

.zoom-level {
    font-weight: 600;
    color: #333;
    min-width: 60px;
    text-align: center;
}

.antialiasing-control {
    margin-left: auto;
}

.antialiasing-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9em;
    color: #555;
    font-weight: 500;
}

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

.zoom-controls {
    display: flex;
    gap: 8px;
}

.zoom-btn {
    padding: 6px 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.zoom-btn:hover {
    background: #764ba2;
    transform: translateY(-1px);
}

.image-focus-canvas-container {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
}

.image-focus-canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
    cursor: grab;
}

.image-focus-canvas-container canvas:active {
    cursor: grabbing;
}

.image-focus-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    font-size: 28px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.image-focus-close:hover {
    background: white;
    transform: scale(1.1);
}

.footer {
    margin-top: 24px;
    text-align: center;
    color: #666;
    font-size: 0.95em;
}

.code-container {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    max-height: 400px;
    overflow: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    white-space: pre;
    color: #333;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    .preview-section {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 1.8em;
    }

    .filter-buttons {
        justify-content: center;
    }
}
