:root {
    color-scheme: light;
    --border-color: #d9defa;
    --bg-color: #f5f7ff;
    --bg-gradient-start: #e7ecff;
    --bg-gradient-end: #f8fbff;
    --surface-color: #ffffff;
    --text-color: #1d2440;
    --muted-text: #66709a;
    --accent-color: #5b5cf0;
    --accent-color-strong: #7e55ff;
    --hover-bg: #edf1ff;
    --history-open-border: #bec8ff;
    --card-active-border: #a8b4e7;
    --card-active-bg: #f4f6ff;
    --navbar-bg: rgba(255, 255, 255, 0.78);
    --navbar-border: #d5dcf9;
    --navbar-glow: rgba(100, 111, 255, 0.24);
    --nav-controls-bg: rgba(255, 255, 255, 0.92);
    --nav-controls-border: #d6ddf9;
    --brand-tagline-color: #5f6994;
    --brand-logo-start: #5b5cf0;
    --brand-logo-end: #7e55ff;
    --brand-logo-overlay: rgba(255, 255, 255, 0.32);
    --brand-logo-shadow: 0 12px 24px rgba(91, 92, 240, 0.34);
    --dropzone-bg-start: #fbfcff;
    --dropzone-bg-end: #f2f5ff;
    --dropzone-drag-bg: #eef4ff;
    --img-box-bg-start: #f0f3ff;
    --img-box-bg-end: #e8eeff;
    --control-icon: #5c6486;
    --control-icon-hover: #1d2440;
    --control-icon-hover-bg: #e8eeff;
    --danger-color: #c62b39;
    --link-color: #3f58dc;
    --input-bg: #ffffff;
    --input-border: #c6cee9;
    --input-placeholder: #8a93b9;
    --focus-ring: rgba(91, 92, 240, 0.2);
    --panel-shadow: 0 10px 26px rgba(47, 76, 188, 0.08);
    --menu-shadow: 0 16px 34px rgba(29, 36, 64, 0.16);
    --button-shadow: 0 8px 18px rgba(91, 92, 240, 0.2);
    --button-shadow-hover: 0 12px 22px rgba(91, 92, 240, 0.26);
    --thumb-shadow: 0 8px 20px rgba(42, 67, 158, 0.08);
}

[data-theme="dark"] {
    color-scheme: dark;
    --border-color: #324068;
    --bg-color: #0f1427;
    --bg-gradient-start: #1b2444;
    --bg-gradient-end: #0c1122;
    --surface-color: #151d35;
    --text-color: #e7ecff;
    --muted-text: #a7b1d8;
    --accent-color: #8895ff;
    --accent-color-strong: #5f7fff;
    --hover-bg: #222d51;
    --history-open-border: #586dab;
    --card-active-border: #6278b7;
    --card-active-bg: #1e2a4c;
    --navbar-bg: rgba(21, 29, 53, 0.8);
    --navbar-border: #3b4a74;
    --navbar-glow: rgba(109, 130, 255, 0.28);
    --nav-controls-bg: rgba(20, 30, 56, 0.92);
    --nav-controls-border: #3f507f;
    --brand-tagline-color: #9da9d3;
    --brand-logo-start: #8796ff;
    --brand-logo-end: #5f7fff;
    --brand-logo-overlay: rgba(255, 255, 255, 0.24);
    --brand-logo-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
    --dropzone-bg-start: #131c36;
    --dropzone-bg-end: #10172d;
    --dropzone-drag-bg: #1c2a4d;
    --img-box-bg-start: #1d2a4b;
    --img-box-bg-end: #1b2542;
    --control-icon: #aab5df;
    --control-icon-hover: #f3f6ff;
    --control-icon-hover-bg: #27335b;
    --danger-color: #ff8a98;
    --link-color: #a9b8ff;
    --input-bg: #151d35;
    --input-border: #43517a;
    --input-placeholder: #7f8ab6;
    --focus-ring: rgba(136, 149, 255, 0.28);
    --panel-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
    --menu-shadow: 0 16px 34px rgba(0, 0, 0, 0.5);
    --button-shadow: 0 8px 18px rgba(88, 114, 255, 0.32);
    --button-shadow-hover: 0 12px 22px rgba(88, 114, 255, 0.42);
    --thumb-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-color);
    background: radial-gradient(circle at top right, var(--bg-gradient-start) 0%, var(--bg-color) 45%, var(--bg-gradient-end) 100%);
    margin: 0;
    padding: 0;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
    flex: 1;
}

.panel {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--surface-color);
    padding: 12px;
    box-shadow: var(--panel-shadow);
}

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

.panel-header h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}


.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
    padding: 10px 14px;
    border: 1px solid var(--navbar-border);
    border-radius: 16px;
    background: var(--navbar-bg);
    backdrop-filter: blur(10px);
    box-shadow: 0 14px 30px -24px var(--navbar-glow);
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
    margin-left: auto;
    padding: 4px 6px;
    border: 1px solid var(--nav-controls-border);
    border-radius: 999px;
    background: var(--nav-controls-bg);
}

.brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: linear-gradient(145deg, var(--brand-logo-start), var(--brand-logo-end));
    color: #fff;
    box-shadow: var(--brand-logo-shadow);
    flex-shrink: 0;
}

.brand-logo::after {
    content: "";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 11px;
    height: 11px;
    border-radius: 4px;
    background: var(--brand-logo-overlay);
}

.brand-logo .material-symbols-outlined {
    font-size: 1.5rem;
    font-variation-settings: "FILL" 1, "wght" 500, "GRAD" 0, "opsz" 24;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.05;
}

.brand-name {
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.brand-tagline {
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    margin-top: 4px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--brand-tagline-color);
}

.header-controls button {
    white-space: nowrap;
}

button {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-color-strong));
    color: #fff;
    border: 1px solid transparent;
    padding: 0 16px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    box-sizing: border-box;
    box-shadow: var(--button-shadow);
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

button:hover {
    opacity: 0.96;
    transform: translateY(-1px);
    box-shadow: var(--button-shadow-hover);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

button.btn-text {
    background: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: none;
}

button.btn-text:hover {
    background: var(--hover-bg);
}

.theme-toggle-btn {
    width: 38px;
    height: 38px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.theme-toggle-btn .material-symbols-outlined {
    font-size: 1.15rem;
}

#historyToggleBtn.history-open {
    background: var(--hover-bg);
    border-color: var(--history-open-border);
}

.drop-zone {
    border: 2px dashed var(--border-color);
    padding: 40px;
    text-align: center;
    color: var(--muted-text);
    margin-bottom: 20px;
    background: linear-gradient(180deg, var(--dropzone-bg-start), var(--dropzone-bg-end));
    border-radius: 14px;
    transition: background 0.2s, border-color 0.2s;
}

.drop-zone.dragover {
    background: var(--dropzone-drag-bg);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

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

.thumbnail {
    border: 1px solid var(--border-color);
    padding: 7px;
    background: var(--surface-color);
    position: relative;
    cursor: grab;
    border-radius: 12px;
    box-shadow: var(--thumb-shadow);
}

.thumbnail:active {
    cursor: grabbing;
}

.img-box {
    height: 120px;
    background: linear-gradient(180deg, var(--img-box-bg-start), var(--img-box-bg-end));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.img-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.controls {
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
}

.controls button {
    background: transparent;
    border: none;
    color: var(--control-icon);
    padding: 2px 5px;
    box-shadow: none;
}

.controls button:hover {
    color: var(--control-icon-hover);
    background: var(--control-icon-hover-bg);
    transform: none;
}

.controls button.delete:hover {
    color: var(--danger-color);
}

.footer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.footer button {
    align-self: stretch;
}

.compression-control {
    display: grid;
    grid-template-columns: auto minmax(140px, 180px) 4ch;
    align-items: center;
    column-gap: 8px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 6px 10px;
    flex: 0 0 auto;
    background: var(--surface-color);
}

.compression-control label {
    font-size: 0.85rem;
    color: var(--muted-text);
    white-space: nowrap;
}

#compressionInput {
    width: 100%;
    margin: 0;
}

#compressionValue {
    font-size: 0.85rem;
    width: 4ch;
    text-align: right;
    color: var(--muted-text);
    font-variant-numeric: tabular-nums;
}

.file-size-info {
    font-size: 0.85rem;
    color: var(--muted-text);
    white-space: nowrap;
    min-width: 160px;
    font-variant-numeric: tabular-nums;
}

.history-section {
    margin-top: 24px;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

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

.history-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-empty {
    margin: 0;
    color: var(--muted-text);
    font-size: 0.9rem;
}

.history-item {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background: var(--surface-color);
}

.history-meta {
    min-width: 0;
}

.history-name {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-details {
    margin: 2px 0 0;
    font-size: 0.8rem;
    color: var(--muted-text);
}

.history-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

.history-actions button {
    padding: 5px 10px;
    font-size: 0.8rem;
}

@media (max-width: 860px) {
    .navbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .brand {
        width: 100%;
    }

    .brand-tagline {
        font-size: 0.69rem;
    }

    .header-controls {
        width: 100%;
        margin-left: 0;
        justify-content: center;
        border-radius: 14px;
        flex-wrap: wrap;
        padding: 8px;
        box-sizing: border-box;
    }

    .footer {
        align-items: stretch;
    }
}

@media (max-width: 560px) {
    .brand-tagline {
        display: none;
    }

    .brand-name {
        font-size: 1.08rem;
    }

    .brand-logo {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }

    .footer {
        flex-direction: column;
        align-items: stretch;
    }
    
    .compression-control {
        grid-template-columns: auto 1fr 4ch;
    }

    .file-size-info {
        text-align: center;
        width: 100%;
    }

    .header-controls button {
        flex: 1;
        padding: 0 8px;
    }
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
}

footer {
    margin: auto 0 0 0;
    font-size: 1.2rem;
    color: var(--muted-text);
    text-align: center;
    padding: 1rem;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

footer a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 600;
}

input {
    border: 1px solid var(--input-border);
    border-radius: 8px;
    outline: none;
    height: 40px;
    box-sizing: border-box;
    padding: 0 12px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.95rem;
}

input::placeholder {
    color: var(--input-placeholder);
}

input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

input[type="text"] {
    flex-grow: 1;
}

.ext {
    color: var(--muted-text);
}

#downloadBtn {
    padding: 8px 20px;
    font-weight: 500;
}
