:root {
    --primary-color: #1b5e3f;
    --accent-color: #f0a500;
    --success-color: #28a745;
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #333;
    --muted-color: #6c757d;
    --border-color: #dee2e6;
}

[data-theme="dark"] {
    --primary-color: #3fa46a;
    --accent-color: #f0a500;
    --success-color: #4caf50;
    --background-color: #1e1e1e;
    --surface-color: #2a2a2a;
    --text-color: #e0e0e0;
    --muted-color: #999999;
    --border-color: #404040;
}

* {
    box-sizing: border-box;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--primary-color);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#blazor-error-ui {
    background: #fff3cd;
    color: #856404;
    padding: 1rem;
    text-align: center;
    display: none;
}

#blazor-error-ui.show,
#blazor-error-ui[style*="display: block"] {
    display: block;
}

#blazor-error-ui a {
    color: #856404;
    margin-left: 0.5rem;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

header {
    background: var(--primary-color);
    color: white;
    padding: 1.5rem;
    text-align: center;
    margin-bottom: 1.5rem;
    position: relative;
}

header h1 {
    margin: 0;
    font-size: 1.75rem;
    outline: none;
}

header p {
    margin: 0.5rem auto 0;
    max-width: 640px;
    opacity: 0.9;
    font-size: 0.9rem;
}

.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.theme-toggle-btn {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.converter {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.file-drop {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 2rem;
    background: var(--surface-color);
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.file-drop:hover {
    border-color: var(--primary-color);
}

.file-drop-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.file-drop-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.file-drop-text strong {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.file-drop-text span {
    color: var(--muted-color);
    font-size: 0.85rem;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.upload-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.upload-or {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--muted-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.upload-or::before,
.upload-or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.sample-btn {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: border-color 0.2s, background 0.2s;
}

.sample-btn:hover:not(:disabled) {
    border-color: var(--primary-color);
}

.sample-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.preview {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.preview img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

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

.progress {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.progress-track {
    position: relative;
    overflow: hidden;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--primary-color);
    transition: width 0.15s ease;
}

.progress-fill-indeterminate {
    width: 40%;
    animation: progress-indeterminate 1.2s ease-in-out infinite;
}

@keyframes progress-indeterminate {
    0% { margin-left: -40%; }
    100% { margin-left: 100%; }
}

.progress-label {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--muted-color);
}

.progress-count {
    font-variant-numeric: tabular-nums;
}

.image-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.download-row {
    display: flex;
}

.no-options {
    margin: 0;
    padding: 1rem 1.5rem;
    color: var(--muted-color, var(--text-color));
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    font-size: 0.9rem;
}

.advanced-options {
    margin-top: 0.75rem;
    padding: 0 1.5rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.advanced-options > summary {
    padding: 1rem 0;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.advanced-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    padding-bottom: 1.5rem;
}

.advanced-section h4 {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted-color, var(--text-color));
}

.option-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.option-row-inline {
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
}

.option-row label {
    font-size: 0.9rem;
}

.option-row-inline label {
    flex: 1;
    min-width: 0;
}

.option-row input[type="number"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background-color);
    color: var(--text-color);
    font-size: 0.9rem;
    width: 100%;
}

.option-row input[type="color"] {
    width: 2.25rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background-color);
    cursor: pointer;
}

.option-row input[type="range"] {
    flex: 1;
    min-width: 60px;
}

.option-row input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
}

.btn-spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.5rem;
    vertical-align: -0.15em;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.convert-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    padding: 1.5rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.format-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 200px;
}

.format-selector label {
    font-weight: 500;
}

.format-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--background-color);
    color: var(--text-color);
    font-size: 0.9rem;
}

.label-toggle {
    flex-direction: row;
    align-items: center;
    flex: 0 0 auto;
    min-width: 0;
}

.label-toggle input {
    width: 1.1rem;
    height: 1.1rem;
}

.convert-btn {
    padding: 0.6rem 1.5rem;
    border: 1px solid var(--primary-color);
    background: var(--primary-color);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.convert-btn:hover {
    opacity: 0.9;
}

.convert-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error {
    padding: 1rem;
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
    border-radius: 8px;
}

.error-message {
    margin: 0;
}

.error-report {
    margin: 0.75rem 0 0;
    font-size: 0.9rem;
}

.error-report a {
    color: #842029;
    font-weight: 600;
}

footer {
    text-align: center;
    padding: 1rem;
    color: var(--muted-color);
    font-size: 0.875rem;
    margin-top: 2rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.footer-version,
.footer-size,
.footer-ram {
    margin-left: 0.5rem;
    opacity: 0.7;
}

@media (max-width: 768px) {
    header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
        text-align: left;
        flex: 1;
        margin-right: 0.5rem;
    }

    header p {
        display: none;
    }

    .theme-toggle {
        position: static;
        flex-shrink: 0;
    }

    .theme-toggle-btn {
        padding: 0.5rem;
        min-width: 36px;
    }

    .theme-toggle-btn .text {
        display: none;
    }

    .theme-toggle-btn .icon {
        font-size: 1.25rem;
    }

    .convert-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .convert-btn {
        width: 100%;
    }

    /* The footer row is tight on a phone; drop the payload-size figure to keep it readable. */
    .footer-size {
        display: none;
    }
}
