/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 10px;
}

header p {
    font-size: 1.1rem;
    color: #7f8c8d;
}

/* Main Content */
main {
    flex: 1;
}

/* Card Component */
.card {
    background: white;
    border-radius: 8px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card h2 {
    margin-bottom: 20px;
    color: #2c3e50;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    padding: 60px 20px;
    text-align: center;
    background-color: #f8f9fa;
    cursor: pointer;
    transition: all 0.3s ease;
}

.drop-zone:hover {
    border-color: #3498db;
    background-color: #e8f4f8;
}

.drop-zone.drag-over {
    border-color: #3498db;
    background-color: #e8f4f8;
    transform: scale(1.02);
}

.drop-zone p {
    margin: 10px 0;
    color: #7f8c8d;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

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

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

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-large {
    padding: 15px 30px;
    font-size: 18px;
    margin-top: 20px;
}

/* Form Elements */
.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #34495e;
}

input[type="number"] {
    width: 100px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
}

/* Slider */
.slider {
    width: 100%;
    margin: 10px 0;
}

/* Optimization Presets */
.optimization-presets {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.optimization-preset {
    flex: 1;
    min-width: 80px;
    padding: 10px 12px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.optimization-preset.active {
    background-color: #3498db;
    color: white;
    font-weight: 500;
}

.optimization-preset:not(.active):hover {
    background-color: #e3f2fd;
    border-color: #3498db;
}

/* Advanced Settings */
#toggle-advanced {
    background: none;
    border: none;
    color: #3498db;
    cursor: pointer;
    font-size: 14px;
    padding: 8px 0;
    text-align: left;
    width: 100%;
    transition: color 0.3s ease;
}

#toggle-advanced:hover {
    color: #2c88c9;
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
    margin-right: 5px;
}

.advanced-settings {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin-top: 10px;
}

/* Fine-tune Controls */
.fine-tune-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.fine-tune-controls span {
    font-size: 14px;
    color: #666;
    white-space: nowrap;
}

#fine-tune {
    flex: 1;
}

/* Radio Groups */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-group label {
    display: flex;
    align-items: center;
    font-weight: normal;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    margin-right: 8px;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 30px;
    background-color: #ecf0f1;
    border-radius: 15px;
    overflow: hidden;
    margin: 20px 0;
}

.progress-fill {
    height: 100%;
    background-color: #3498db;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

#progress-text {
    text-align: center;
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
}

#progress-status {
    text-align: center;
    color: #7f8c8d;
    margin: 10px 0;
}

#progress-details {
    text-align: center;
    color: #95a5a6;
    font-size: 14px;
}

/* Results */
.gif-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin: 30px 0;
}

.gif-panel {
    text-align: center;
}

.gif-panel h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

/* Loading state for GIF comparison */
.gif-comparison.loading .gif-panel {
    position: relative;
    min-height: 200px;
}

.gif-comparison.loading .gif-panel::before {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #7f8c8d;
    font-style: italic;
    z-index: 1;
}

.comparison-gif {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: block;
    margin: 0 auto;
}

.media-container {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.unsupported-format {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.unsupported-format p {
    margin: 10px 0;
}

.unsupported-format .format-name {
    font-size: 14px;
    font-style: italic;
}

.gif-info {
    margin-top: 15px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.gif-info p {
    margin: 5px 0;
    font-size: 14px;
}

.size-reduction {
    color: #27ae60;
    font-weight: 500;
}

/* Removed frames gallery */
#removed-frames-section {
    margin: 30px 0;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

#removed-frames-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
}

#removed-frames-gallery {
    display: flex;
    overflow-x: auto;
    gap: 15px;
    padding: 15px 0;
    margin: 0 -10px;
    padding-left: 10px;
    padding-right: 10px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: thin;
    scrollbar-color: #bdc3c7 #ecf0f1;
}

#removed-frames-gallery::-webkit-scrollbar {
    height: 8px;
}

#removed-frames-gallery::-webkit-scrollbar-track {
    background: #ecf0f1;
    border-radius: 4px;
}

#removed-frames-gallery::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 4px;
}

#removed-frames-gallery::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

.removed-frame-container {
    flex-shrink: 0;
    text-align: center;
}

.removed-frame-thumb {
    height: 120px;
    width: auto;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: block;
}

.removed-frame-thumb:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.removed-frame-number {
    text-align: center;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    font-weight: 500;
}

/* Modal for enlarged frame view */
.frame-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    overflow: auto;
}

.frame-modal-content {
    position: relative;
    margin: auto;
    padding: 20px;
    max-width: 90%;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.frame-modal-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.frame-modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.frame-modal-close:hover,
.frame-modal-close:focus {
    color: #bbb;
}

.frame-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #f1f1f1;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    padding: 10px;
    user-select: none;
    z-index: 1001;
}

.frame-modal-prev {
    left: 20px;
}

.frame-modal-next {
    right: 20px;
}

.frame-modal-nav:hover {
    color: #bbb;
}

.frame-modal-caption {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: #ccc;
    font-size: 16px;
}

.stat h3 {
    font-size: 14px;
    color: #7f8c8d;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.stat p {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
}

.results-details {
    margin-bottom: 20px;
    line-height: 2;
}

.results-details p {
    color: #555;
}

.results-details span {
    font-weight: bold;
    color: #2c3e50;
}

.results-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

/* Error Section */
.error {
    border: 2px solid #e74c3c;
    background-color: #ffe6e6;
}

.error h2 {
    color: #e74c3c;
}

#error-message {
    color: #c0392b;
    margin-bottom: 20px;
}

/* File Info */
.file-info {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.file-info p {
    margin: 5px 0;
}

.file-info span {
    font-weight: bold;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px 0;
    color: #7f8c8d;
    font-size: 14px;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .gif-comparison {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .optimization-presets {
        flex-direction: column;
    }
    
    .optimization-preset {
        width: 100%;
        min-width: unset;
    }
    
    .fine-tune-controls {
        flex-wrap: wrap;
    }
    
    .fine-tune-controls span {
        font-size: 12px;
    }
    
    #fine-tune {
        width: 100%;
        margin: 10px 0;
    }
    
    .advanced-settings {
        padding: 15px;
    }
    
    .results-actions {
        flex-direction: column;
    }
    
    .results-actions .btn {
        width: 100%;
    }
    
    #removed-frames-gallery {
        margin: 0 -5px;
        padding-left: 5px;
        padding-right: 5px;
    }
    
    .removed-frame-thumb {
        height: 80px;
    }
    
    .frame-modal-nav {
        font-size: 24px;
        padding: 5px;
    }
    
    .frame-modal-close {
        font-size: 30px;
        right: 20px;
    }
}

/* Video-only options */
#dithering-group {
    display: none;
}

/* Loading Animation */
@keyframes pulse {
    0% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 0.6;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Command line display */
.command-line-display {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 100%;
    border: 1px solid #333;
}

#command-line-section {
    margin-top: 20px;
}

#command-line-section h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}