/* --- Global Reset & Modern Design --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --danger: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
    --bg-gradient: linear-gradient(-45deg, #667eea, #764ba2, #f093fb, #4facfe);
    --card-bg: rgba(255, 255, 255, 0.95);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    --shadow-hover: 0 25px 80px rgba(0, 0, 0, 0.25);
    --text-dark: #2d3748;
    --text-light: #718096;
    --border-radius: 16px;
}

body {
    /* ใช้ฟอนต์ Sarabun ที่เพิ่มเข้ามา */
    font-family: 'Sarabun', sans-serif;
    background: var(--bg-gradient);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

h1 {
    color: white;
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 2rem;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: fadeInDown 0.8s ease;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 650px;
    padding: 3rem;
    animation: fadeInUp 0.8s ease;
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-5px);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-group {
    margin-bottom: 2rem;
}

.form-label {
    display: block;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.form-select {
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23667eea' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 20px;
}

.form-select:hover {
    border-color: #667eea;
}

.form-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.quality-control {
    padding: 1.5rem;
    background: linear-gradient(135deg, #f6f8fb 0%, #e9ecf5 100%);
    border-radius: 12px;
    margin-bottom: 2rem;
}

.quality-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.quality-value {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.form-range {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 10px;
    outline: none;
    appearance: none;
}

.form-range::-webkit-slider-thumb {
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.upload-area {
    position: relative;
    margin-bottom: 1rem;
}

#imageInput {
    display: none;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: var(--primary);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.4);
}

.upload-btn:active {
    transform: translateY(0);
}

.upload-btn::before {
    content: "📁";
    font-size: 1.5rem;
}

.instruction-text {
    text-align: center;
    color: var(--text-light);
    font-size: 0.9rem;
    margin-top: 0.75rem;
}

#outputArea {
    margin-top: 2rem;
}

.file-item {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.file-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.file-name {
    font-weight: 500;
    color: var(--text-dark);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.download-link {
    padding: 0.5rem 1.25rem;
    background: var(--success);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(17, 153, 142, 0.3);
}

.download-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(17, 153, 142, 0.4);
}

.download-all-btn {
    display: none;
    width: 100%;
    padding: 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: var(--success);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 1.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 8px 20px rgba(17, 153, 142, 0.3);
}

.download-all-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(17, 153, 142, 0.4);
}

.download-all-btn::before {
    content: "📦 ";
}

.processing {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
    font-size: 1.1rem;
}

.processing::after {
    content: "...";
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

@media (max-width: 640px) {
    h1 {
        font-size: 2rem;
    }
    
    .card {
        padding: 2rem 1.5rem;
    }

    .file-item {
        flex-direction: column;
        gap: 1rem;
    }

    .download-link {
        width: 100%;
        text-align: center;
    }
}