/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-color-rgb: 99, 102, 241;
    --accent-color: #22d3ee;
    --primary-color-light: rgba(99, 102, 241, 0.16);
    --bg-gradient-start: #eef2ff;
    --bg-gradient-end: #e0f2fe;
    --bg-primary: rgba(255, 255, 255, 0.92);
    --bg-secondary: rgba(255, 255, 255, 0.7);
    --surface-color: rgba(255, 255, 255, 0.85);
    --border-color: rgba(99, 102, 241, 0.12);
    --text-color: #1f2937;
    --text-secondary: #64748b;
    --text-muted: #64748b;
    --danger-color: #ef4444;
    --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
    --shadow-lg: 0 30px 60px rgba(15, 23, 42, 0.18);
    --glass-border: rgba(255, 255, 255, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #818cf8;
        --primary-hover: #6366f1;
        --primary-color-rgb: 129, 140, 248;
        --accent-color: #38bdf8;
        --primary-color-light: rgba(129, 140, 248, 0.2);
        --bg-gradient-start: #0f172a;
        --bg-gradient-end: #1f2937;
        --bg-primary: rgba(15, 23, 42, 0.78);
        --bg-secondary: rgba(30, 41, 59, 0.72);
        --surface-color: rgba(15, 23, 42, 0.82);
        --border-color: rgba(148, 163, 184, 0.18);
        --text-color: #e2e8f0;
        --text-secondary: #cbd5f5;
        --text-muted: #a5b4fc;
        --danger-color: #f87171;
        --shadow: 0 24px 60px rgba(2, 6, 23, 0.55);
        --shadow-lg: 0 40px 80px rgba(2, 6, 23, 0.6);
        --glass-border: rgba(148, 163, 184, 0.35);
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(99, 102, 241, 0.18), transparent 55%),
        radial-gradient(circle at bottom right, rgba(34, 211, 238, 0.16), transparent 50%),
        linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0));
    mix-blend-mode: screen;
    z-index: -1;
}

/* PDF Converter Styles */
.container {
    max-width: 1200px;
    margin: 3rem auto;
    padding: 3rem;
    background: var(--surface-color);
    border-radius: 28px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(24px);
}

/* Features Preview */
.features-preview {
    margin-bottom: 3rem;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.feature-card {
    background: linear-gradient(135deg, rgba(var(--primary-color-rgb), 0.12), rgba(255, 255, 255, 0.7));
    border: 1px solid rgba(var(--primary-color-rgb), 0.16);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(14px);
}

.feature-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 24px 45px rgba(var(--primary-color-rgb), 0.18);
    border-color: rgba(var(--primary-color-rgb), 0.35);
}

.feature-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

.feature-card:hover::before {
    left: 100%;
}

.feature-icon {
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.85), rgba(var(--primary-color-rgb), 0.9));
    border-radius: 24px;
    width: 76px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    box-shadow: 0 20px 35px rgba(var(--primary-color-rgb), 0.28);
}

.feature-icon svg {
    width: 40px;
    height: 40px;
    fill: white;
}

.feature-card h3 {
    color: var(--text-color);
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.feature-card p {
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
    margin: 0;
}

/* Mode selector styles */
.conversion-mode-selector {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    background: var(--surface-color);
    border-radius: 12px;
    padding: 4px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.mode-btn {
    flex: 1;
    max-width: 200px;
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(var(--primary-color-rgb), 0.3);
}

.mode-btn:hover:not(.active) {
    background: rgba(var(--primary-color-rgb), 0.1);
    color: var(--primary-color);
}

/* Bidirectional conversion card enhancements */
.feature-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem;
}

.conversion-arrow {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: bold;
    margin: 0 8px;
}

.pdf-icon {
    font-size: 2rem;
    margin: 0;
}

.hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .conversion-mode-selector {
        flex-direction: column;
        gap: 4px;
    }
    
    .mode-btn {
        max-width: none;
    }
    
    .feature-card {
        padding: 1.25rem;
        gap: 0.5rem;
    }
    
    .conversion-arrow {
        font-size: 1.25rem;
    }
    
    .pdf-icon {
        font-size: 1.75rem;
    }
}

.start-converting-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 1.25rem 2.5rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 24px rgba(var(--primary-color-rgb), 0.3);
    position: relative;
    overflow: hidden;
}

.start-converting-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(var(--primary-color-rgb), 0.4);
}

.start-converting-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.start-converting-btn:hover::before {
    left: 100%;
}

/* Usage Documentation */
.usage-documentation {
    margin-top: 3rem;
    border-top: 2px solid var(--border-color);
    padding-top: 2rem;
}

.usage-toggle {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 2rem;
    width: 100%;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.usage-toggle:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.usage-toggle::after {
    content: '▼';
    transition: transform 0.3s ease;
    margin-left: 0.5rem;
}

.usage-toggle.active::after {
    transform: rotate(180deg);
}

.usage-content {
    margin-top: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    animation: slideDown 0.3s ease-out;
}

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

.usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.usage-section {
    background: var(--bg-primary);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.usage-section:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.usage-section h3 {
    color: var(--primary-color);
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.usage-section p {
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}

.format-details {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.format-details h3 {
    color: var(--text-color);
    font-size: 1.3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.format-list {
    display: grid;
    gap: 0.75rem;
}

.format-item {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    transition: all 0.3s ease;
}

.format-item:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.format-item strong {
    color: var(--primary-color);
    font-weight: 700;
    margin-right: 0.5rem;
}

.format-item span {
    color: var(--text-muted);
    line-height: 1.5;
}

.tips-section {
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color-light), var(--bg-secondary));
    border-radius: 12px;
    border: 1px solid var(--primary-color);
}

.tips-section h3 {
    color: var(--primary-color);
    font-size: 1.3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.tips-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tips-section li {
    color: var(--text-color);
    line-height: 1.6;
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
    position: relative;
}

.tips-section li::before {
    content: '💡';
    position: absolute;
    left: 0;
    top: 0;
}

.tips-section li:last-child {
    margin-bottom: 0;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-size: 2.5rem;
    font-weight: 700;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 0;
}

/* Tabs */
.tool-tabs {
    display: flex;
    margin-bottom: 2rem;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--glass-border);
    padding: 0.5rem;
    border-radius: 14px;
    backdrop-filter: blur(12px);
}

.tab-button {
    background: none;
    border: none;
    padding: 0.9rem 1.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 10px;
}

.tab-button:hover {
    color: var(--primary-color);
    background-color: rgba(var(--primary-color-rgb), 0.08);
}

.tab-button.active {
    color: var(--primary-color);
    background: rgba(var(--primary-color-rgb), 0.18);
    box-shadow: inset 0 0 0 1px rgba(var(--primary-color-rgb), 0.25);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Upload Area */
.upload-area {
    border: 1px dashed rgba(var(--primary-color-rgb), 0.28);
    border-radius: 18px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    margin-bottom: 2rem;
}

.upload-area:hover {
    border-color: rgba(var(--primary-color-rgb), 0.55);
    background: rgba(255, 255, 255, 0.75);
    transform: translateY(-4px);
    box-shadow: 0 20px 45px rgba(var(--primary-color-rgb), 0.2);
}

.upload-area.dragover {
    border-color: rgba(var(--primary-color-rgb), 0.65);
    background: rgba(255, 255, 255, 0.85);
    transform: translateY(-6px);
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    width: 4rem;
    height: 4rem;
    fill: var(--primary-color);
    margin-bottom: 1rem;
}

.upload-icon.uploaded {
    fill: #10b981;
}

.file-info {
    font-size: 0.9rem !important;
    color: var(--text-secondary) !important;
    margin-top: 0.5rem !important;
}

.upload-area p {
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.supported-formats {
    font-size: 0.9rem !important;
    color: var(--text-muted) !important;
}

/* Options Section */
.options-section {
    background: rgba(255, 255, 255, 0.58);
    padding: 2rem;
    border-radius: 18px;
    margin-bottom: 2rem;
    border: 1px solid var(--glass-border);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(14px);
}

.option-group {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.option-group label {
    min-width: 120px;
    font-weight: 600;
    color: var(--text-color);
}

.option-group select,
.option-group input[type="range"],
.option-group input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-primary);
    color: var(--text-color);
}

.option-group input[type="text"] {
    margin-left: 0.5rem;
    max-width: 200px;
}

.option-group input[type="range"] {
    max-width: 200px;
}

#quality-value {
    min-width: 40px;
    font-weight: 600;
    color: var(--primary-color);
}

/* Buttons */
.convert-btn,
.download-btn,
.download-all-btn,
.reset-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
    text-decoration: none;
    margin: 0.5rem;
}

.convert-btn:hover,
.download-btn:hover,
.download-all-btn:hover,
.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.reset-btn {
    background: linear-gradient(135deg, var(--danger-color), #dc2626);
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    border-radius: 50px;
    z-index: 100;
}

/* Results Section */
.results-section {
    background: rgba(255, 255, 255, 0.58);
    padding: 2rem;
    border-radius: 18px;
    text-align: center;
    border: 1px solid var(--glass-border);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(14px);
}

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

.result-item {
    background: rgba(255, 255, 255, 0.78);
    padding: 1rem;
    border-radius: 14px;
    border: 1px solid rgba(var(--primary-color-rgb), 0.12);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.1);
}

.result-item img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.result-item .page-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.result-item .download-btn {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    margin: 0;
}

/* Selected Images */
.selected-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.image-item {
    position: relative;
    background: rgba(255, 255, 255, 0.82);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid rgba(var(--primary-color-rgb), 0.14);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.image-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
}

.image-item .remove-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* PDF Preview */
.pdf-preview {
    background-color: var(--bg-primary);
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.pdf-preview canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.pdf-preview p {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .tab-button {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
    
    .option-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .option-group label {
        min-width: auto;
    }
    
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .selected-images {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
    
    .reset-btn {
        bottom: 1rem;
        right: 1rem;
        padding: 0.75rem 1.5rem;
    }
}

/* Format Hint Styles */
.format-hint {
    margin-bottom: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color-light), rgba(var(--primary-color-rgb), 0.1));
    border: 1px solid rgba(var(--primary-color-rgb), 0.2);
    border-radius: 8px;
    animation: slideIn 0.3s ease-out;
}

.hint-content {
    color: var(--primary-color);
    font-weight: 500;
    text-align: center;
    font-size: 0.95rem;
}

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