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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px;
    padding-top: max(70px, calc(env(safe-area-inset-top) + 50px));
    color: #fff;
}

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: rgba(16, 18, 36, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.site-header-logo {
    font-size: 0.85rem;
    font-weight: bold;
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.site-nav {
    display: flex;
    gap: 4px;
}

.site-nav button {
    color: #888;
    text-decoration: none;
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.site-nav button:hover {
    color: #fff;
    background: rgba(255,255,255,0.08);
}

.site-nav button.active {
    color: #00d4ff;
    background: rgba(0, 212, 255, 0.1);
}

.tool-page {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.tool-page.active {
    display: flex;
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: #888;
    margin-bottom: 25px;
    font-size: 0.85rem;
}

.main-container {
    display: flex;
    gap: 25px;
    width: 100%;
    max-width: 1000px;
    flex-wrap: wrap;
    justify-content: center;
}

.left-panel {
    flex: 1;
    min-width: 280px;
    max-width: 480px;
}

.right-panel {
    flex: 1;
    min-width: 280px;
    max-width: 420px;
}

.drop-zone {
    width: 100%;
    height: 180px;
    border: 3px dashed #444;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255,255,255,0.02);
    margin-bottom: 15px;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: #00d4ff;
    background: rgba(0, 212, 255, 0.05);
    transform: scale(1.02);
}

.drop-zone-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.drop-zone-text {
    font-size: 0.95rem;
    color: #aaa;
}

.drop-zone-hint {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
}

.preview-section {
    background: rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 15px;
}

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

.preview-title {
    font-size: 0.85rem;
    color: #aaa;
}

.preview-size {
    font-size: 0.8rem;
    color: #4ade80;
    font-weight: bold;
}

.preview-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: repeating-conic-gradient(#333 0% 25%, #222 0% 50%) 50% / 20px 20px;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.preview-placeholder {
    color: #555;
    font-size: 0.85rem;
    text-align: center;
    padding: 20px;
}

.preview-compare {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.compare-btn {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
    background: rgba(255,255,255,0.1);
    color: #aaa;
}

.compare-btn.active {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    color: #fff;
}

.settings {
    background: rgba(255,255,255,0.05);
    padding: 16px;
    border-radius: 16px;
    margin-bottom: 15px;
}

.settings-title {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    color: #aaa;
    font-size: 0.85rem;
    min-width: 45px;
}

.setting-row input[type="range"] {
    flex: 1;
    accent-color: #00d4ff;
    height: 6px;
}

.quality-value {
    color: #00d4ff;
    font-weight: bold;
    min-width: 45px;
    text-align: right;
    font-size: 0.9rem;
}

.quality-note {
    font-size: 0.7rem;
    color: #666;
    margin-top: -4px;
    margin-bottom: 10px;
    padding-left: 57px;
}

.resize-section {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 12px;
    margin-top: 4px;
}

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

.resize-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.resize-toggle input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    width: 36px;
    height: 20px;
    background: #444;
    border-radius: 10px;
    position: relative;
    transition: background 0.3s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}

.resize-toggle input:checked + .toggle-switch,
.meta-toggle input:checked + .toggle-switch {
    background: #00d4ff;
}

.resize-toggle input:checked + .toggle-switch::after,
.meta-toggle input:checked + .toggle-switch::after {
    transform: translateX(16px);
}

.resize-toggle span {
    color: #aaa;
    font-size: 0.85rem;
}

.original-dims {
    font-size: 0.7rem;
    color: #666;
}

.resize-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.4;
    pointer-events: none;
    transition: opacity 0.3s;
}

.resize-controls.enabled {
    opacity: 1;
    pointer-events: auto;
}

.resize-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.resize-input label {
    font-size: 0.7rem;
    color: #666;
}

.resize-input input {
    width: 100%;
    padding: 8px;
    background: rgba(255,255,255,0.08);
    border: 1px solid #444;
    border-radius: 8px;
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.resize-input input:focus {
    border-color: #00d4ff;
}

.resize-input input::placeholder {
    color: #555;
}

.aspect-lock {
    background: none;
    border: 1px solid #444;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    margin-top: 16px;
    color: #888;
}

.aspect-lock.locked {
    border-color: #00d4ff;
    color: #00d4ff;
    background: rgba(0, 212, 255, 0.1);
}

.meta-section {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 12px;
    margin-top: 4px;
}

.meta-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.meta-toggle input[type="checkbox"] {
    display: none;
}

.meta-toggle span {
    color: #aaa;
    font-size: 0.85rem;
}

.meta-note {
    font-size: 0.7rem;
    color: #666;
    margin-top: 6px;
    padding-left: 44px;
}

.format-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: bold;
    text-transform: uppercase;
}

.format-badge.jpeg {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.format-badge.png {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

.bulk-actions {
    display: none;
    gap: 8px;
    margin-bottom: 12px;
}

.bulk-actions.visible {
    display: flex;
}

.bulk-btn {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border: none;
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    transition: transform 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
}

.bulk-btn:hover {
    transform: scale(1.03);
    opacity: 0.9;
}

.bulk-btn.clear {
    background: rgba(255,255,255,0.1);
    flex: 0;
    padding: 10px 14px;
}

.bulk-btn.clear:hover {
    background: rgba(255,100,100,0.3);
}

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

.results {
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
}

.result-item {
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-info {
    flex: 1;
    min-width: 0;
}

.result-name {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.result-stats {
    font-size: 0.7rem;
    color: #888;
}

.result-stats .saved {
    color: #4ade80;
    font-weight: bold;
}

.result-stats .increased {
    color: #f87171;
    font-weight: bold;
}

.download-btn {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border: none;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: transform 0.2s, opacity 0.2s;
    margin-left: 8px;
    flex-shrink: 0;
    text-decoration: none;
}

.download-btn:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.processing {
    color: #fbbf24;
}

input[type="file"] {
    display: none;
}

.stats-summary {
    padding: 8px 14px;
    background: rgba(74, 222, 128, 0.1);
    border-radius: 10px;
    color: #4ade80;
    font-size: 0.8rem;
    margin-bottom: 12px;
    display: none;
}

.stats-summary.visible {
    display: block;
}

.convert-btn {
    width: 100%;
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border: none;
    color: #fff;
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: bold;
    transition: transform 0.2s, opacity 0.2s;
    display: none;
}

.convert-btn.visible {
    display: block;
}

.convert-btn:hover {
    transform: scale(1.02);
    opacity: 0.9;
}

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

.install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.9);
    border: 1px solid #333;
    border-radius: 12px;
    padding: 12px 20px;
    display: none;
    align-items: center;
    gap: 12px;
    z-index: 1000;
}

.install-prompt.visible {
    display: flex;
}

.install-prompt span {
    font-size: 0.85rem;
    color: #aaa;
}

.install-btn {
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
}

.install-close {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 4px;
}

/* --- Progress Bar --- */
.progress-section {
    margin-bottom: 12px;
    display: none;
}
.progress-section.visible {
    display: block;
}
.progress-bar-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #00d4ff, #7b2cbf);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}
.progress-text {
    font-size: 0.75rem;
    color: #aaa;
    display: flex;
    justify-content: space-between;
}
.progress-text .progress-percent {
    color: #00d4ff;
    font-weight: bold;
}

/* --- File Queue --- */
.file-queue {
    display: none;
    margin-bottom: 12px;
}
.file-queue.visible {
    display: block;
}
.file-queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.file-queue-header .queue-info {
    font-size: 0.75rem;
    color: #aaa;
}
.file-queue-header .queue-clear-btn {
    background: none;
    border: none;
    color: #666;
    font-size: 0.7rem;
    cursor: pointer;
    transition: color 0.2s;
}
.file-queue-header .queue-clear-btn:hover {
    color: #f87171;
}
.queue-list {
    max-height: 200px;
    overflow-y: auto;
}
.queue-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    margin-bottom: 4px;
    animation: slideIn 0.2s ease;
}
.queue-item-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    object-fit: cover;
    background: rgba(0,0,0,0.3);
    flex-shrink: 0;
}
.queue-item-info {
    flex: 1;
    min-width: 0;
}
.queue-item-name {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #ccc;
}
.queue-item-size {
    font-size: 0.65rem;
    color: #666;
}
.queue-item-remove {
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.queue-item-remove:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

/* --- Cancel State --- */
.convert-btn.cancel-mode {
    background: rgba(248, 113, 113, 0.3);
    border: 1px solid rgba(248, 113, 113, 0.5);
}
.convert-btn.cancel-mode:hover {
    background: rgba(248, 113, 113, 0.5);
}
