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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border: #475569;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* Light Theme */
body.light-theme {
    --bg: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
}

body.light-theme {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, #1e293b 100%);
    color: var(--text);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
    position: relative;
}

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

.theme-toggle {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.5rem;
    color: var(--text);
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
    transform: scale(1.1);
    border-color: var(--primary);
}

.theme-icon {
    transition: transform 0.3s ease;
}

/* Additional light theme styles for better visibility */
body.light-theme .presets-section {
    background: #f8fafc;
    border-color: #e2e8f0;
}

body.light-theme .progress-section,
body.light-theme .results-section,
body.light-theme .history-section,
body.light-theme .images-grid,
body.light-theme .api-section {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

body.light-theme .progress-item,
body.light-theme .result-card,
body.light-theme .result-item,
body.light-theme .history-item {
    background: #f8fafc;
    border-color: #e2e8f0;
}

body.light-theme .progress-bar {
    background: #e2e8f0;
}

body.light-theme .btn-secondary {
    background: #f1f5f9;
    color: var(--text);
    border-color: #cbd5e1;
}

body.light-theme .btn-secondary:hover {
    background: #e2e8f0;
    border-color: var(--primary);
}

body.light-theme .preset-btn {
    background: #ffffff;
    border-color: #cbd5e1;
    color: var(--text);
}

body.light-theme .preset-btn:hover {
    background: #f8fafc;
    border-color: var(--primary);
}

body.light-theme .preset-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

body.light-theme .bg-preset-btn {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-theme .bg-preset-btn:hover {
    background: #f8fafc;
}

body.light-theme .user-preset-btn {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-theme .user-preset-btn:hover {
    background: #f8fafc;
    border-color: var(--primary);
}

body.light-theme .modal-content {
    background: #ffffff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

body.light-theme .comparison-preview,
body.light-theme .result-thumbnail,
body.light-theme .image-preview {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

header h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    margin-bottom: 30px;
}

.upload-area {
    border: 3px dashed var(--border);
    border-radius: 20px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-secondary);
}

body.light-theme .upload-area {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.light-theme .upload-area:hover {
    background: #f8fafc;
    border-color: var(--primary);
}

.upload-area:hover {
    border-color: var(--primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.upload-area.dragover {
    border-color: var(--primary);
    background: var(--bg-tertiary);
    transform: scale(1.02);
}

.upload-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    stroke-width: 2;
    color: var(--primary);
}

.upload-content h2 {
    margin-bottom: 10px;
    color: var(--text);
}

.upload-content p {
    color: var(--text-secondary);
    margin: 5px 0;
}

.formats {
    font-size: 0.9rem;
    margin-top: 15px;
    color: var(--text-secondary);
}

/* Settings Panel */
.settings-panel {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px var(--shadow);
}

body.light-theme .settings-panel {
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.settings-panel h3 {
    margin-bottom: 25px;
    font-size: 1.5rem;
}

.settings-panel h4 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: var(--text);
}

/* Settings Sections */
.settings-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.basic-settings {
    background: var(--bg-secondary);
}

.collapsible-section {
    cursor: pointer;
}

.collapsible-section summary {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    padding: 10px 0;
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}

.collapsible-section summary:hover {
    color: var(--primary);
}

.collapsible-section summary::-webkit-details-marker {
    display: none;
}

.collapsible-section summary::before {
    content: '▶';
    display: inline-block;
    margin-right: 10px;
    transition: transform 0.3s ease;
    color: var(--primary);
}

.collapsible-section[open] summary::before {
    transform: rotate(90deg);
}

.collapsible-section[open] summary {
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

body.light-theme .settings-section {
    background: #f8fafc;
    border-color: #e2e8f0;
}

body.light-theme .basic-settings {
    background: #ffffff;
}

/* Presets Section */
.presets-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid var(--border);
}

/* Custom Size List Section */
.custom-size-list-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid var(--border);
}

.add-size-form {
    margin-bottom: 20px;
}

.size-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.size-input {
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 1rem;
    width: 120px;
}

.size-separator {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.custom-sizes-list {
    min-height: 100px;
    margin-bottom: 20px;
}

.custom-size-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.custom-size-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary);
}

.size-item-info {
    flex: 1;
}

.size-item-main {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 5px;
}

.size-item-dimensions {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
}

.size-item-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.size-item-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.btn-icon:hover {
    background: var(--border);
    border-color: var(--primary);
}

.btn-icon.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.custom-list-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.empty-message {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-style: italic;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-row label {
    font-weight: 500;
    color: var(--text);
}

.modal-input {
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-size: 1rem;
}

body.light-theme .custom-size-list-section {
    background: #f8fafc;
}

body.light-theme .custom-size-item {
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light-theme .custom-size-item:hover {
    background: #f8fafc;
    border-color: var(--primary);
}

body.light-theme .size-input,
body.light-theme .modal-input {
    background: #ffffff;
    border-color: #e2e8f0;
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.preset-btn {
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    font-weight: 500;
}

.preset-btn:hover {
    border-color: var(--primary);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.preset-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.preset-info {
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.bg-color-options {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.bg-preset-btn {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.bg-preset-btn:hover {
    background: var(--border);
    transform: scale(1.05);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.setting-group {
    display: flex;
    flex-direction: column;
}

.setting-group label {
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text);
}

.setting-group input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.setting-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

.setting-group input[type="number"],
.setting-group select,
.setting-group input[type="color"] {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    font-size: 1rem;
    transition: all 0.2s ease;
}

body.light-theme .setting-group input[type="number"],
body.light-theme .setting-group select,
body.light-theme .setting-group input[type="color"] {
    background: #ffffff;
    border-color: #e2e8f0;
}

body.light-theme .setting-group input[type="number"]:focus,
body.light-theme .setting-group select:focus,
body.light-theme .setting-group input[type="color"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.setting-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    cursor: pointer;
}

.setting-group label:has(input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
}

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px var(--shadow);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px var(--shadow);
}

/* Images Grid */
.images-grid {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.images-grid h3 {
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.image-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 15px;
    border: 1px solid var(--border);
    transition: transform 0.3s ease;
}

body.light-theme .image-card {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.image-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px var(--shadow);
}

body.light-theme .image-card:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.image-preview {
    width: 100%;
    height: 200px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg);
    margin-bottom: 15px;
}

.image-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.image-info strong {
    color: var(--text);
}

.image-name {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    word-break: break-all;
}

/* Progress Section */
.progress-section {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.progress-section h3 {
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.progress-item {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 10px;
}

.progress-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.progress-bar {
    width: 100%;
    height: 25px;
    background: var(--bg);
    border-radius: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.results-section h3 {
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.result-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.result-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 15px;
}

.comparison-item {
    text-align: center;
}

.comparison-item h4 {
    margin-bottom: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.comparison-preview {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg);
    margin-bottom: 10px;
}

.size-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.size-saved {
    color: var(--success);
    font-weight: 600;
}

.download-actions {
    text-align: center;
    margin-top: 25px;
}

/* Results Grid for Multiple Sizes */
.result-group {
    margin-bottom: 30px;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.result-item {
    background: var(--bg);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--border);
    text-align: center;
    transition: transform 0.3s ease;
}

.result-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px var(--shadow);
}

.result-thumbnail {
    width: 100%;
    max-width: 150px;
    height: 150px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg-secondary);
    margin-bottom: 10px;
}

.result-details {
    text-align: center;
}

.result-name {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    font-size: 0.9rem;
    word-break: break-word;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
    margin-top: 10px;
}

/* API Section */
.api-section {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.api-section details {
    cursor: pointer;
}

.api-section summary {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.api-content {
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.api-content pre {
    background: var(--bg);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 15px 0;
}

.api-content code {
    color: var(--primary);
    font-family: 'Courier New', monospace;
}

.note {
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 15px;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer p {
    margin: 5px 0;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--border);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* History Section */
.history-section {
    background: var(--bg-secondary);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.history-item {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 15px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.history-item:hover {
    transform: translateY(-2px);
}

.history-item img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 10px;
}

/* User Presets */
.user-presets-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

.user-presets-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.user-preset-btn {
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    position: relative;
}

.user-preset-btn:hover {
    border-color: var(--primary);
}

.user-preset-btn .delete-preset {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-size: 12px;
    display: none;
}

.user-preset-btn:hover .delete-preset {
    display: block;
}

.preset-percentages {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.percent-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text);
    cursor: pointer;
    font-size: 0.85rem;
}

.percent-btn:hover {
    background: var(--border);
}

.keyboard-help {
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
}

.keyboard-help kbd {
    background: var(--bg);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-family: monospace;
    font-size: 0.85rem;
}

.keyboard-help ul {
    list-style: none;
    padding: 0;
    margin-top: 15px;
}

.keyboard-help li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.keyboard-help li:last-child {
    border-bottom: none;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

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

    .comparison {
        grid-template-columns: 1fr;
    }

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

    .btn {
        width: 100%;
    }
}

/* Loading Animation */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

