:root {
    /* Premium Glassmorphism Dark Theme */
    --bg-dark: #09090b;
    /* Very dark zinc */
    --bg-gradient: linear-gradient(135deg, #09090b 0%, #171720 100%);

    /* Vibrant Gradients & Accents */
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-gradient-hover: linear-gradient(135deg, #4f46e5 0%, #9333ea 100%);
    --accent-color: #8b5cf6;

    /* Status Colors */
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --error-color: #ef4444;

    /* Shadows */
    --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.3);

    /* Structure */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-round: 99px;

    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 20px;
    --space-lg: 32px;
    --space-xl: 48px;

    /* Safe Area Variables for Mobile */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);

    /* Theme-specific variables (dark default) */
    --bg-main: #09090b;
    --bg-radial-1: rgba(99, 102, 241, 0.1);
    --bg-radial-2: rgba(168, 85, 247, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-bg-hover: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.05);
    --glass-border-light: rgba(255, 255, 255, 0.1);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --btn-secondary-bg: rgba(255, 255, 255, 0.03);
    --btn-secondary-text: #ffffff;
    --heading-gradient: linear-gradient(180deg, #ffffff 0%, #a1a1aa 100%);
    --bottom-bar-bg: linear-gradient(0deg, rgba(9, 9, 11, 1) 60%, rgba(9, 9, 11, 0) 100%);
    --shadow-main: 0 4px 30px rgba(0, 0, 0, 0.15);
    --input-bg: rgba(255, 255, 255, 0.03);
    --upload-border: rgba(255, 255, 255, 0.15);
    --upload-bg: rgba(255, 255, 255, 0.01);
    --file-list-item-bg: rgba(255, 255, 255, 0.02);
    --file-list-item-hover: rgba(255, 255, 255, 0.05);
    --toast-bg: rgba(255, 255, 255, 0.9);
    --toast-color: #000;
    --disabled-color: rgba(255, 255, 255, 0.3);
    --success-color: #10b981;
}

[data-theme="light"] {
    --bg-main: #f4f6fb;
    --bg-radial-1: rgba(99, 102, 241, 0.06);
    --bg-radial-2: rgba(168, 85, 247, 0.06);
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-bg-hover: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-border-light: rgba(0, 0, 0, 0.1);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --btn-secondary-bg: #ffffff;
    --btn-secondary-text: #0f172a;
    --heading-gradient: linear-gradient(180deg, #1e293b 0%, #64748b 100%);
    --bottom-bar-bg: linear-gradient(0deg, #f4f6fb 60%, rgba(244, 246, 251, 0) 100%);
    --shadow-main: 0 4px 24px rgba(0, 0, 50, 0.06);
    --input-bg: rgba(0, 0, 0, 0.03);
    --upload-border: rgba(0, 0, 0, 0.12);
    --upload-bg: rgba(255, 255, 255, 0.5);
    --file-list-item-bg: rgba(0, 0, 0, 0.02);
    --file-list-item-hover: rgba(0, 0, 0, 0.04);
    --toast-bg: #1e293b;
    --toast-color: #ffffff;
    --disabled-color: rgba(0, 0, 0, 0.25);
    --success-color: #059669;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    background-image: radial-gradient(circle at 15% 50%, var(--bg-radial-1), transparent 25%),
        radial-gradient(circle at 85% 30%, var(--bg-radial-2), transparent 25%);
    background-size: cover;
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.5;
    height: 200vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    /* Prevent pull-to-refresh */
    transition: background 0.3s ease, color 0.3s ease;
}

/* Base App Wrapper - Simulates Mobile App Frame */
#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Screening architecture */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95) translateY(10px);
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: scale(1) translateY(0);
    z-index: 2;
}

/* Headers */
header {
    padding: calc(var(--space-xl) + var(--safe-area-inset-top)) var(--space-md) var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
    z-index: 10;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--heading-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
    user-select: none;
}

.theme-toggle {
    margin-left: auto;
}

.theme-toggle i {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.theme-toggle:active i {
    transform: rotate(180deg);
}

[data-theme="light"] .theme-toggle i {
    color: #f59e0b;
}

/* Layout */
main {
    flex: 1;
    padding: 0 var(--space-md);
    overflow-y: auto;
    overflow-x: hidden;
    /* Remove fixed bottom padding since we're using flexbox for bottom bar */
    display: flex;
    flex-direction: column;
    /* smooth scroll and safe gutters */
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

main.content-center {
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* Blur backdrop for fixed bottom bars */
.bottom-bar {
    position: relative;
    margin-top: auto;
    width: 100%;
    /* Increase bottom padding to lift the button higher as requested */
    padding: var(--space-md) var(--space-md) calc(var(--space-xl) + var(--safe-area-inset-bottom));
    background: var(--bottom-bar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 10;
}

.double-buttons {
    display: flex;
    gap: var(--space-sm);
}

/* 🎨 Glass Components */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-main);
    transition: background 0.3s ease, border 0.3s ease;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 16px;
    border-radius: var(--radius-round);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
    user-select: none;
    touch-action: manipulation;
}

.primary-btn {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.25);
}

.primary-btn:hover:not(:disabled),
.primary-btn:active:not(:disabled) {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 20px rgba(99, 102, 241, 0.4);
    background: var(--accent-gradient-hover);
}

.primary-btn:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
}

.primary-btn:disabled {
    background: var(--glass-bg);
    color: var(--disabled-color);
    border: 1px solid var(--glass-border);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

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

.secondary-btn:hover,
.secondary-btn:active {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-light);
}

/* Icon Buttons */
.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    user-select: none;
    touch-action: manipulation;
}

.icon-btn:hover {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-light);
}

/* Screen 1: Upload Area */
.upload-area {
    width: 100%;
    border: 2px dashed var(--upload-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl) var(--space-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--upload-bg);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.05);
    box-shadow: inset 0 0 30px rgba(139, 92, 246, 0.1);
}

.upload-icon {
    font-size: 3.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--space-md);
    filter: drop-shadow(0 4px 8px rgba(99, 102, 241, 0.3));
    animation: float 6s ease-in-out infinite;
}

.upload-area h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.upload-area p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.file-limits {
    font-size: 0.8rem !important;
    opacity: 0.6;
    margin-top: 8px;
}

/* File Selection Indicator */
.selected-file-info {
    width: 100%;
    padding: var(--space-md);
    margin-top: var(--space-lg);
    border: 1px solid rgba(139, 92, 246, 0.3);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(99, 102, 241, 0.05) 100%);
    border-radius: var(--radius-md);
    animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.file-details {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: 4px;
}

.file-details i {
    color: #ef4444;
    /* PDF Color */
    font-size: 1.5rem;
}

.file-details span {
    flex: 1;
    font-weight: 500;
    font-size: 1.05rem;
}

.file-size {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: 36px;
}

/* Screen 2: Preview & Options */
.preview-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-xl) var(--space-md);
    margin-bottom: var(--space-lg);
}

.preview-summary .file-icon-large {
    font-size: 4rem;
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 8px 16px rgba(239, 68, 68, 0.3));
    margin-bottom: var(--space-md);
}

.page-count-badge {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border-light);
    padding: 6px 14px;
    border-radius: var(--radius-round);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: var(--space-sm);
    color: var(--text-secondary);
}

.options-heading {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
    padding-left: 4px;
}

.option-card {
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    /* Increased gap */
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
    user-select: none;
    touch-action: manipulation;
    min-height: 84px;
    /* Increased height */
}

.option-card.active {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.4);
}

.option-card.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent-gradient);
    border-radius: 4px 0 0 4px;
}

.radio-custom {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.radio-custom input {
    display: none;
}

.radio-custom label {
    position: relative;
    cursor: pointer;
    padding-left: 26px;
}

.radio-custom label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    transition: all 0.2s;
    box-sizing: border-box;
}

.option-card.active .radio-custom label:before {
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}

.option-card.active .radio-custom label:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 6px;
    transform: translateY(-50%) scale(1);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-color);
    animation: popIn 0.2s ease-out forwards;
}

.option-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.option-content h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.option-content p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}


.password-input-wrapper {
    margin-top: var(--space-md);
}

.error-text {
    color: var(--error-color);
    font-size: 0.8rem;
    margin-top: 6px;
}

/* Screen 3: Processing */
.loader-wrapper {
    position: relative;
    width: 140px;
    height: 140px;
    margin-bottom: var(--space-xl);
}

.loader-circle {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--glass-border);
    position: relative;
}

.loader-circle::after {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--accent-color);
    animation: spin 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

.loader-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: pulse 2s infinite;
}

#screen-processing h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

#screen-processing p {
    color: var(--text-secondary);
}

/* Screen 4: Success */
.success-header-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    text-align: center;
}

.success-icon-large {
    font-size: 3.5rem;
    background: var(--success-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 12px rgba(16, 185, 129, 0.3));
    margin-bottom: 8px;
}

.file-list-card {
    padding: var(--space-md);
}

.file-list-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: var(--space-sm);
}

.file-list-heading h3 {
    font-size: 1rem;
    font-weight: 600;
}

.file-list-heading span {
    background: var(--glass-bg-hover);
    padding: 2px 8px;
    border-radius: var(--radius-round);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.file-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--file-list-item-bg);
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.file-item:hover {
    background: var(--file-list-item-hover);
}

.file-item-icon {
    font-size: 1.25rem;
    color: #ef4444;
}

.file-item-name {
    flex: 1;
    font-size: 0.95rem;
}

.btn-icon-dl {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-color);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-dl:hover {
    background: rgba(99, 102, 241, 0.2);
    transform: scale(1.05);
}

/* Utils */
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.hidden {
    display: none !important;
}

/* Toast Configuration */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--toast-bg);
    color: var(--toast-color);
    padding: 12px 24px;
    border-radius: var(--radius-round);
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 999;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

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

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        opacity: 0.7;
        transform: translate(-50%, -50%) scale(0.9);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* 📱 Responsive Adjustments */
@media (max-width: 400px) {
    :root {
        --space-md: 16px;
        --space-lg: 24px;
        --space-xl: 32px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .upload-icon {
        font-size: 3rem;
    }

    .preview-summary .file-icon-large {
        font-size: 3.5rem;
    }

    .btn {
        padding: 14px;
        font-size: 1rem;
    }
}
}

@media (max-height: 700px) {
    header {
        padding-top: var(--space-lg);
    }

    .preview-summary {
        padding: var(--space-md);
        margin-bottom: var(--space-md);
    }
}

/* Landscape Mode Fix */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        overflow-y: auto;
        height: auto;
        min-height: 100dvh;
    }

    #app-container {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .screen {
        position: relative;
        height: auto;
        min-height: 100dvh;
    }

    .bottom-bar {
        position: sticky;
        bottom: 0;
    }
}