:root {
    --bg-color: #0c0d12;
    --surface-color: rgba(255, 255, 255, 0.05);
    --surface-border: rgba(255, 255, 255, 0.1);
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-color: #ffcc33; /* Soft amber night light */
    --accent-glow: rgba(255, 204, 51, 0.4);
    --primary-gradient: linear-gradient(135deg, #1a1c2c 0%, #0c0d12 100%);
    --glass-bg: rgba(30, 32, 44, 0.7);
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Spacing System */
    --space-2xs: 4px;
    --space-xs: 8px;
    --space-sm: 16px;
    --space-md: 24px;
    --space-lg: 32px;
    --space-xl: 48px;
    --space-2xl: 64px;
}


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

body {
    background-color: var(--bg-color);
    background-image: var(--primary-gradient);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body scroll, screens handle their own scroll */
    line-height: 1.6;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes glowPulse {
    0% { box-shadow: 0 0 5px var(--accent-glow); }
    50% { box-shadow: 0 0 20px var(--accent-glow); }
    100% { box-shadow: 0 0 5px var(--accent-glow); }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(255, 204, 51, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 204, 51, 0); }
}

.pulse {
    animation: pulse 2s infinite;
    border-color: var(--accent-color) !important;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-md);
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

header {
    margin-bottom: var(--space-xl);
    animation: fadeIn 0.8s ease-out;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.brand {
    text-align: left;
}


h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    background: linear-gradient(to right, var(--accent-color), #ff9933);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}


.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

/* Screen Transitions */
.screen {
    display: none;
    height: 100%;
    flex-direction: column;
    animation: fadeIn 0.5s ease-out forwards;
    overflow-y: auto;
    padding-bottom: var(--space-lg);
}

.screen.active {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Import Screen */
#import-screen {
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.upload-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: 24px;
    padding: 3rem 2rem;
    text-align: center;
    width: 100%;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.upload-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.upload-icon {
    font-size: 3rem;
    color: var(--accent-color);
    margin-bottom: 1.5rem;
    display: block;
}

.upload-text h3 {
    margin-bottom: 0.5rem;
}

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

#file-input {
    display: none;
}

/* Library Screen */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end; /* Align to baseline */
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--surface-border);
}

.header-actions {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.pdf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-md);
}

.pdf-card {
    background: var(--glass-bg);
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transition: var(--transition);
    position: relative;
    cursor: pointer;
}


.pdf-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-5px);
}

.pdf-card h3 {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-card .meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.delete-pdf-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 100, 100, 0.1);
    color: #ff6464;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    opacity: 0;
}

.pdf-card:hover .delete-pdf-btn {
    opacity: 1;
}

.delete-pdf-btn:hover {
    background: #ff6464;
    color: #fff;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

/* Settings Modal Refinement */
.settings-view {
    max-width: 440px;
    width: 95%;
    background: rgba(12, 13, 18, 0.98);
    border: 1px solid var(--surface-border);
    border-radius: 24px;
    padding: var(--space-md) var(--space-lg);
    box-shadow: 0 30px 60px rgba(0,0,0,0.8);
    position: relative;
}

.settings-header {
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--surface-border);
    padding-bottom: var(--space-xs);
}

.settings-header h3 {
    font-size: 1.25rem;
    color: var(--accent-color);
}

.settings-header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.settings-sections {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.settings-section .section-head {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
    color: var(--accent-color);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    opacity: 0.9;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: var(--space-sm);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: var(--transition);
    margin-bottom: var(--space-xs);
}

.setting-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 204, 51, 0.3);
    transform: translateX(4px);
}

.full-width {
    width: 100%;
    justify-content: center;
}

.setting-info label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
}

.setting-info small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Styled Select */
.styled-select {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--surface-border);
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23ffcc33' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    min-width: 180px;
}

.styled-select:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-color);
}

.styled-select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(255, 204, 51, 0.2);
}

.styled-select option {
    background: #1a1c2c;
    color: var(--text-primary);
    padding: 10px;
}
.page-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.page-list::-webkit-scrollbar {
    width: 4px;
}

.page-list::-webkit-scrollbar-thumb {
    background: var(--surface-border);
    border-radius: 4px;
}

.page-item {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.page-item:hover {
    background: rgba(255, 204, 51, 0.15);
    border-color: var(--accent-color);
    transform: scale(1.02);
}

.page-item.selected {
    background: var(--accent-color);
    color: #000;
}

.page-item.read {
    border-color: rgba(0, 255, 127, 0.3);
    position: relative;
}

.page-item.read::after {
    content: '✓';
    position: absolute;
    top: 5px;
    right: 5px;
    color: #00ff7f;
    font-size: 0.8rem;
}

/* Reader Screen */
.reader-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--surface-border);
    border-radius: 32px;
    padding: 2.5rem;
    height: 400px; /* Fixed height for better control */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.reading-content {
    font-size: 1.75rem;
    font-weight: 500;
    text-align: center;
    word-break: break-word;
    flex: 1;
    overflow-y: auto;
    padding: 2rem 0;
    scroll-behavior: smooth;
    mask-image: linear-gradient(to bottom, transparent, black 15%, black 85%, transparent);
}

.reading-content::-webkit-scrollbar {
    display: none; /* Hide scrollbar for cleaner karaoke look */
}


.word-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    transition: transform 0.2s ease-out;
}

.word {
    display: inline-block;
    color: var(--text-secondary);
    transition: var(--transition);
    opacity: 0.4;
}

.word.active {
    color: var(--accent-color);
    opacity: 1;
    transform: scale(1.2);
    text-shadow: 0 0 15px var(--accent-glow);
}

.word.read {
    color: var(--text-primary);
    opacity: 0.8;
}

/* Controls */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 2rem;
}

.primary-controls {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping for mobile */
}


.button {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    padding: 1rem 2rem;
    border-radius: 100px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.button:hover {
    background: var(--surface-border);
    transform: translateY(-2px);
}

.button.primary {
    background: var(--accent-color);
    color: #000;
    border: none;
    padding: 1.25rem 3rem;
    font-size: 1.1rem;
    box-shadow: 0 8px 24px rgba(255, 204, 51, 0.2);
}

.button.primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 32px rgba(255, 204, 51, 0.3);
}

.button.icon-btn {
    padding: 0;
    width: 40px;
    height: 40px;
    justify-content: center;
    font-size: 1.25rem;
    border-radius: 12px;
}
.button.primary.round {
    width: 70px; /* Slightly smaller for mobile compatibility */
    height: 70px;
    padding: 0;
    justify-content: center;
    font-size: 1.75rem;
    position: relative;
    flex-shrink: 0;
}



.button.nav-btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    background: var(--surface-color);
    border-radius: 12px;
}

.button.nav-btn:not(:disabled):hover {
    background: var(--surface-border);
    border-color: var(--accent-color);
}

.button.nav-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}


.settings-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-color);
    padding: 1rem 1.5rem;
    border-radius: 16px;
    font-size: 0.9rem;
    flex-wrap: wrap; /* Allow wrapping */
}


.speed-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

input[type="range"] {
    accent-color: var(--accent-color);
}

.voice-toggle {
    display: flex;
    align-items: center;
}

.toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    position: relative;
}

.toggle input {
    display: none;
}

.slider {
    width: 40px;
    height: 20px;
    background: var(--surface-border);
    border-radius: 20px;
    position: relative;
    transition: var(--transition);
}

.slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--text-secondary);
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: var(--transition);
}

.toggle input:checked + .slider {
    background: var(--accent-color);
}

.toggle input:checked + .slider::before {
    transform: translateX(20px);
    background: #000;
}

.toggle .label {
    font-size: 0.85rem;
}

/* Mobile Adjustments */
@media (max-width: 480px) {
    :root {
        --space-md: 16px;
        --space-lg: 24px;
    }

    .app-container {
        padding: var(--space-sm);
    }

    h1 { font-size: 1.8rem; }
    .subtitle { font-size: 0.75rem; }

    header {
        margin-bottom: var(--space-md);
    }

    .reader-active header {
        display: none !important;
    }

    /* Library Fixes */
    .pdf-grid {
        grid-template-columns: 1fr;
    }

    /* Reader Screen - App Style */
    #reader-screen {
        display: none;
        flex-direction: column;
        height: 100%;
        padding-bottom: 0;
        overflow: hidden;
    }

    #reader-screen.active {
        display: flex;
    }

    .reader-container { 
        flex: 1;
        height: auto;
        min-height: 0;
        margin-bottom: var(--space-sm);
        padding: 1.5rem;
        border-radius: 24px;
    }

    .reading-content { 
        font-size: 1.5rem;
        padding: 1rem 0;
    }

    .controls-panel {
        margin-top: 0;
        background: var(--glass-bg);
        backdrop-filter: blur(20px);
        margin: 0 -16px; /* Bleed to edges */
        padding: var(--space-xs) 16px env(safe-area-inset-bottom, 16px);
        border-top: 1px solid var(--surface-border);
        border-radius: 24px 24px 0 0;
        gap: 0.75rem;
        z-index: 10;
        flex-shrink: 0;
    }

    .controls-handle {
        width: 36px;
        height: 4px;
        background: var(--surface-border);
        border-radius: 2px;
        margin: 0 auto var(--space-xs) auto;
        opacity: 0.5;
    }

    .settings-bar { 
        padding: 0.75rem;
        background: rgba(255,255,255,0.03);
        border: none;
        gap: 0.5rem;
    }

    .settings-bar > div {
        flex: 1;
        justify-content: center;
        font-size: 0.8rem;
    }
    
    .speed-control { gap: 0.5rem; }
    .speed-control input { width: 80px; }

    .primary-controls { 
        gap: 1.25rem; 
        justify-content: space-evenly;
    }

    .button.primary.round {
        width: 64px;
        height: 64px;
        font-size: 1.5rem;
    }

    .button.nav-btn {
        padding: 0.6rem 1rem;
        background: rgba(255,255,255,0.05);
    }

    .keyboard-hint { display: none !important; }
}

/* Mute Toggle in Reader */
.mute-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition);
    padding: 0.5rem;
}

.mute-btn:hover {
    color: var(--accent-color);
}

/* Settings Modal Specifics */
.music-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.music-option {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: var(--space-xs);
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
    font-size: 0.85rem;
}

.music-option:hover {
    border-color: var(--accent-color);
}

.music-option.selected {
    background: rgba(255, 204, 51, 0.2);
    border-color: var(--accent-color);
}

.upload-option {
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-style: dashed;
    background: rgba(255, 255, 255, 0.02);
}

.track-name-hint {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


