/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #242838;
    --border: #2a2e3a;
    --text: #e4e4e7;
    --text-muted: #9ca3af;
    --accent: #0ea5e9;
    --accent-hover: #38bdf8;
    --accent-glow: rgba(14, 165, 233, 0.15);
    --green: #22c55e;
    --red: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Header ===== */
header {
    text-align: center;
    padding: 2.5rem 1rem 1rem;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ===== Main ===== */
main {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem 1.25rem 3rem;
}

/* ===== Drop Zone ===== */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--bg-card);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.drop-zone-content p {
    font-size: 1.05rem;
}

.browse-link {
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.browse-link:hover {
    color: var(--accent-hover);
}

.formats {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

/* ===== Settings ===== */
.settings {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-top: 1.25rem;
    animation: slideUp 0.3s ease;
}

.settings h2 {
    font-size: 1.1rem;
    margin-bottom: 1.25rem;
    font-weight: 600;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

.setting-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Select */
select {
    appearance: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color var(--transition);
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
}

select:hover, select:focus {
    border-color: var(--accent);
    outline: none;
}

/* Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

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

/* Resize Controls */
.resize-group {
    grid-column: 1 / -1;
}

.resize-mode-toggle {
    display: flex;
    gap: 0;
    background: var(--bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    width: fit-content;
}

.resize-mode {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.resize-mode.active {
    background: var(--accent);
    color: #fff;
}

.resize-mode:hover:not(.active) {
    color: var(--text);
    background: var(--bg-hover);
}

.resize-inputs {
    margin-top: 0.75rem;
}

.dimension-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dimension-inputs input {
    width: 120px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.dimension-inputs input:focus {
    border-color: var(--accent);
    outline: none;
}

.aspect-lock {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--accent);
    padding: 0.4rem;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
}

.aspect-lock:hover {
    border-color: var(--accent);
}

.aspect-lock:not(.locked) {
    color: var(--text-muted);
    opacity: 0.5;
}

.percent-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.percent-input input {
    width: 100px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.percent-input input:focus {
    border-color: var(--accent);
    outline: none;
}

.percent-input span {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Action Bar */
.action-bar {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn.primary {
    background: var(--accent);
    color: #fff;
}

.btn.primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

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

.btn.secondary:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn.small {
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
}

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

/* ===== Progress ===== */
#progress-section {
    margin-top: 1.25rem;
    animation: slideUp 0.3s ease;
}

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

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

#progress-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    text-align: center;
}

/* ===== Results ===== */
.results {
    margin-top: 1.5rem;
    animation: slideUp 0.3s ease;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.results-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.results-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#total-saved {
    font-size: 0.85rem;
    color: var(--green);
    font-weight: 500;
}

.results-grid {
    display: grid;
    gap: 1rem;
}

/* Result Card */
.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: fadeIn 0.3s ease;
}

.result-card-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.result-side {
    padding: 1rem;
}

.result-side:first-child {
    border-right: 1px solid var(--border);
}

.result-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.result-image-wrap {
    background: repeating-conic-gradient(#1e2130 0% 25%, #252838 0% 50%) 50% / 16px 16px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 16/10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-image-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.result-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.result-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.result-savings {
    font-size: 0.85rem;
    font-weight: 500;
}

.result-savings.smaller {
    color: var(--green);
}

.result-savings.larger {
    color: var(--red);
}

.result-filename {
    font-size: 0.8rem;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Footer ===== */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    opacity: 0.6;
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

/* ===== Animations ===== */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    header {
        padding: 1.5rem 1rem 0.75rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .drop-zone {
        padding: 2rem 1.25rem;
    }

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

    .result-card-inner {
        grid-template-columns: 1fr;
    }

    .result-side:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .results-summary {
        width: 100%;
        justify-content: space-between;
    }

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

    .btn {
        justify-content: center;
    }

    .dimension-inputs {
        flex-wrap: wrap;
    }

    .dimension-inputs input {
        width: 100px;
    }

    .result-footer {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
}
