:root {
    --bg-color: #e3e5e8;
    --card-bg: #ffffff;
    --paper-bg: #fdfbf7;
    --text-color: #2c2c2e;
    --primary-color: #007aff;
    --accent-color: #5856d6;
    --success-color: #34c759;
    --border-radius: 16px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --font-ui: 'Inter', sans-serif;
    --font-read: 'Merriweather', serif;
}

/* Auto Dark Mode (can be overridden by class) */
@media (prefers-color-scheme: dark) {
    :root:not(.light-mode):not(.sepia-mode) {
        --bg-color: #121212;
        --card-bg: #1c1c1e;
        --paper-bg: #252525;
        --text-color: #e0e0e0;
        --primary-color: #0a84ff;
        --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    height: 90vh;
}

header {
    text-align: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    font-size: 1.1rem;
    opacity: 0.8;
}

/* Drop Zone */
.drop-zone {
    background: var(--card-bg);
    border: 2px dashed rgba(128, 128, 128, 0.3);
    border-radius: var(--border-radius);
    padding: 60px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: var(--shadow);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

.drop-zone .icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* Buttons */
.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 20px;
    transition: opacity 0.2s;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-success {
    background: var(--success-color);
    color: white;
    border: none;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover,
.btn-success:hover {
    opacity: 0.9;
}

/* Controls */
.controls {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 200px;
}

input[type="range"] {
    width: 100%;
}

/* Reader View */
.reader-view {
    background: var(--paper-bg);
    color: #111;
    padding: 0;
    border-radius: var(--border-radius);
    flex-grow: 1;
    box-shadow: var(--shadow);
    font-family: var(--font-read);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.content {
    flex-grow: 1;
    height: 100%;
}

.text-content {
    padding: 40px;
    overflow-y: auto;
    line-height: 1.8;
    font-size: 1.2rem;
    height: 100%;
    color: #222;
}

.text-content b {
    font-weight: 700;
    color: #000;
}

/* Navigation for EPUB */
.epub-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.05);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    min-height: 50px;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary-color);
    padding: 0 10px;
}

/* Progress Bar */
/* Progress Bar */
.progress-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 15px;
    gap: 8px;
    min-width: 200px;
}

#page-info {
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.9;
    font-variant-numeric: tabular-nums;
    color: var(--primary-color);
    /* Make it stand out */
}

.progress-track {
    width: 100%;
    height: 8px;
    /* Thicker */
    background: rgba(0, 0, 0, 0.2);
    /* Darker track */
    border-radius: 4px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

@media (prefers-color-scheme: dark) {
    .progress-track {
        background: rgba(255, 255, 255, 0.2);
    }
}


/* Utilities */
.hidden {
    display: none !important;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 40px;
}

/* Sepia Theme */
body.sepia-mode {
    --bg-color: #f4ecd8;
    --card-bg: #fdf6e3;
    --paper-bg: #f4ecd8;
    --text-color: #5b4636;
    --primary-color: #8b6b5d;
}

body.dark-mode {
    --bg-color: #121212;
    --card-bg: #1c1c1e;
    --paper-bg: #252525;
    --text-color: #e0e0e0;
    --primary-color: #0a84ff;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Settings Panel */
.settings-container {
    position: relative;
    display: inline-block;
}

.settings-panel {
    position: absolute;
    bottom: 50px;
    right: 0;
    width: 250px;
    background: var(--card-bg);
    color: var(--text-color);
    /* Ensure text color matches theme */
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Force specific colors for visibility if needed, but var(--text-color) should work if set correctly.
   The issue in the screenshot looked like black text on dark bg.
   Let's ensure the panel background is opaque and high contrast.
*/
body.dark-mode .settings-panel {
    background: #2c2c2e;
    /* Slightly lighter than pure black */
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.7;
    margin-bottom: 4px;
}

.theme-toggles {
    display: flex;
    gap: 8px;
}

.theme-btn {
    flex: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.05);
    font-size: 1.2rem;
    transition: all 0.2s;
}

.theme-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.theme-btn.active {
    border-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.08);
}

.theme-btn.light {
    color: #f39c12;
}

.theme-btn.sepia {
    color: #8b6b5d;
}

.theme-btn.dark {
    color: #9b59b6;
}

.font-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    padding: 4px;
}

.font-btn {
    background: none;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-color);
    border-radius: 4px;
}

.font-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

#font-size-display {
    font-size: 0.9rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 16px;
    }

    .app-container {
        height: auto;
        min-height: 90vh;
    }

    header h1 {
        font-size: 2rem;
    }

    .drop-zone {
        padding: 30px 20px;
    }

    .drop-zone .icon {
        font-size: 2.5rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .control-group {
        min-width: 100%;
    }

    .reader-view {
        height: 60vh;
        /* Fixed height on mobile for scrolling */
    }

    .text-content {
        padding: 20px;
        font-size: 1.1rem;
    }

    /* Compact Navigation */
    .epub-nav {
        padding: 10px;
    }

    .progress-wrapper {
        min-width: 0;
        /* Allow shrinking */
        margin: 0 10px;
    }

    #page-info {
        font-size: 0.8rem;
    }

    .nav-btn {
        padding: 0 5px;
    }
}