/* Core Design System & Theme Variables */
:root {
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Pitch Black Dark Mode (Default) */
    --bg-main: hsl(0, 0%, 0%);
    --bg-card: hsl(0, 0%, 6%);
    --bg-header: hsla(0, 0%, 0%, 0.75);
    --border-color: hsl(0, 0%, 15%);
    --text-primary: hsl(0, 0%, 98%);
    --text-secondary: hsl(0, 0%, 75%);
    --accent: hsl(263, 70%, 50%);
    --accent-hover: hsl(263, 70%, 60%);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --btn-danger: hsl(354, 70%, 54%);
    --btn-danger-hover: hsl(354, 70%, 64%);
}

/* Light Theme Override */
[data-app-theme="light"] {
    --bg-main: hsl(210, 20%, 96%);
    --bg-card: hsl(0, 0%, 100%);
    --bg-header: hsla(210, 20%, 96%, 0.75);
    --border-color: hsl(210, 20%, 88%);
    --text-primary: hsl(222, 47%, 11%);
    --text-secondary: hsl(215, 16%, 47%);
    --accent: hsl(263, 70%, 50%);
    --accent-hover: hsl(263, 70%, 40%);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
}

/* Sepia Theme Override */
[data-app-theme="sepia"] {
    --bg-main: hsl(36, 33%, 89%);
    --bg-card: hsl(36, 30%, 94%);
    --bg-header: hsla(36, 33%, 89%, 0.75);
    --border-color: hsl(36, 15%, 80%);
    --text-primary: hsl(36, 40%, 15%);
    --text-secondary: hsl(36, 20%, 40%);
    --accent: hsl(25, 70%, 45%);
    --accent-hover: hsl(25, 70%, 35%);
    --shadow: 0 8px 32px 0 rgba(139, 90, 43, 0.1);
}

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

body, html {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    width: 100%;
    height: 100%;
    overflow: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.screen.active {
    display: flex;
    opacity: 1;
    z-index: 10;
}

/* Headers */
.glass-header {
    background: var(--bg-header);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
    z-index: 100;
}

/* Form Styles (Login Screen) */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, hsl(222, 47%, 8%) 0%, hsl(222, 47%, 14%) 100%);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px;
    width: 90%;
    max-width: 440px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.logo {
    margin-bottom: 32px;
}

.logo i {
    font-size: 48px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 16px;
}

.logo h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.input-group {
    text-align: left;
    margin-bottom: 24px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 16px;
    color: var(--text-secondary);
}

.input-wrapper input {
    width: 100%;
    padding: 14px 16px 14px 48px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: var(--font-sans);
    transition: all 0.3s ease;
}

[data-app-theme="light"] .input-wrapper input {
    background: rgba(0, 0, 0, 0.02);
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.help-text {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* Buttons */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-icon.danger {
    color: var(--btn-danger);
}

.btn-icon.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-icon-text {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.btn-icon-text:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Library Container */
.library-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.section-title h2 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Book Grid layout */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 24px;
    width: 100%;
}

/* Book Cards */
.book-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--accent);
}

.book-cover-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    margin-bottom: 12px;
}

.book-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.book-card:hover .book-cover {
    transform: scale(1.05);
}

.book-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-author {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: auto;
    overflow: hidden;
}

.card-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.card-progress-label {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

/* Spinner / Loader */
.loader-container {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Reader Screen Layout */
#reader-screen {
    background-color: var(--bg-main);
}

.reader-header {
    height: 60px;
    padding: 0 16px;
}

.reader-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.reader-main {
    flex: 1;
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#viewer {
    width: 100%;
    height: 100%;
    padding: 0;
    max-width: 800px;
    background: transparent;
    overflow: hidden;
}

/* EpubJS Render Adjustments */
#viewer iframe {
    background: transparent !important;
}

.tap-zone {
    position: absolute;
    top: 60px;
    bottom: 60px;
    width: 15%;
    z-index: 10;
    cursor: pointer;
}

.tap-left {
    left: 0;
}

.tap-right {
    right: 0;
}

.reader-footer {
    height: 60px;
    border-top: 1px solid var(--border-color);
    border-bottom: none;
    padding: 0 16px;
}

.btn-page-nav {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.progress-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    max-width: 60%;
}

.progress-info span {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.progress-bar-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Settings Menu / Modal */
.settings-menu {
    position: absolute;
    top: 70px;
    right: 16px;
    width: 280px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    z-index: 101;
    animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-menu.hidden {
    display: none;
}

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

.settings-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
}

.setting-group {
    margin-bottom: 16px;
}

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

.setting-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.size-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 4px;
}

.btn-pill {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.btn-pill:hover {
    background: rgba(255, 255, 255, 0.1);
}

.theme-controls {
    display: flex;
    gap: 8px;
}

.theme-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-btn[data-theme="light"] {
    background: hsl(0, 0%, 96%);
    color: hsl(222, 47%, 11%);
}

.theme-btn[data-theme="dark"] {
    background: hsl(0, 0%, 10%);
    color: hsl(0, 0%, 98%);
}

.theme-btn[data-theme="sepia"] {
    background: hsl(36, 30%, 94%);
    color: hsl(36, 40%, 15%);
}

.theme-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

.font-controls {
    display: flex;
    gap: 8px;
}

.font-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

[data-app-theme="light"] .font-btn {
    background: hsl(0, 0%, 96%);
    color: hsl(222, 47%, 11%);
}

[data-app-theme="dark"] .font-btn {
    background: hsl(0, 0%, 10%);
    color: hsl(0, 0%, 98%);
}

[data-app-theme="sepia"] .font-btn {
    background: hsl(36, 30%, 94%);
    color: hsl(36, 40%, 15%);
}

.font-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    transition: opacity 0.3s ease;
    box-shadow: 0 8px 16px rgba(0,0,0,0.25);
    pointer-events: none;
    text-align: center;
    white-space: nowrap;
}

.toast.hidden {
    opacity: 0;
}

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

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

/* Table of Contents Drawer */
.toc-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 320px;
    height: 100%;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    z-index: 101;
    display: flex;
    flex-direction: column;
    padding: 24px;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toc-menu.hidden {
    display: flex;
    transform: translateX(-100%);
}

.toc-menu .settings-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 12px;
}

/* Drawer Backdrop */
.drawer-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    opacity: 1;
    visibility: visible;
}

.drawer-backdrop.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.toc-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 10px;
    padding-right: 4px;
}

.toc-item {
    display: block;
    padding: 12px 14px;
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--accent);
}

.toc-item.active {
    background: rgba(124, 58, 237, 0.15);
    color: var(--accent);
    font-weight: 600;
}

/* Custom Scrollbar for TOC list */
.toc-list::-webkit-scrollbar {
    width: 6px;
}
.toc-list::-webkit-scrollbar-track {
    background: transparent;
}
.toc-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Progress Slider styling with enhanced mobile touch target */
.progress-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    padding: 10px 0;
    background-clip: content-box;
    transition: background 0.3s;
}

[data-app-theme="light"] .progress-slider {
    background: rgba(0, 0, 0, 0.1);
    background-clip: content-box;
}

.progress-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    border-radius: 4px;
}

.progress-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: transform 0.1s;
}

.progress-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    background: var(--accent-hover);
}

/* Sync Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--accent-color);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10000;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    pointer-events: none;
}

.toast.toast-error {
    background-color: #ef4444;
}

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