/* Library Header */
.library-header {
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-content {
    width: 100%;
    max-width: var(--content-max-width);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.library-header h1 {
    font-size: 1.5rem;
    color: var(--text-color);
}

/* Library Content */
.library-content {
    flex: 1;
    padding: 20px;
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* Book Grid */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 30px 20px;
    padding-bottom: 80px;
    /* Space for bottom interaction */
}

/* Book Item */
.book-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.book-item:active {
    transform: scale(0.96);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    background-color: #f0f0f0;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    position: relative;
    margin-bottom: 12px;
    transition: box-shadow 0.2s;
}

[data-theme="dark"] .book-cover {
    background-color: #333;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.book-item:hover .book-cover {
    box-shadow: var(--shadow-lg);
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-cover .placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-color-secondary);
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.02) 0%, rgba(0, 0, 0, 0.05) 100%);
}

.book-cover .placeholder i {
    font-size: 2rem;
    margin-bottom: 5px;
}

.book-title {
    width: 100%;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.book-author {
    width: 100%;
    font-size: 0.8rem;
    color: var(--text-color-secondary);
    text-align: center;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    height: 60vh;
}

.empty-icon {
    font-size: 4rem;
    color: var(--text-color-secondary);
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--text-color);
}

.empty-state p {
    color: var(--text-color-secondary);
    font-size: 1rem;
}

/* Delete Action (visible on long press or specific mode) */
.delete-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ff3b30;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* --- Profile & Menu --- */
.profile-section {
    padding: 30px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid var(--border-color);
}

.profile-avatar {
    width: 60px;
    height: 60px;
    background: var(--accent-color);
    color: var(--bg-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.profile-info h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.profile-info p {
    font-size: 0.9rem;
    color: var(--text-color-secondary);
}

.menu-list {
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:active {
    background: rgba(0, 0, 0, 0.05);
}

.menu-item i:first-child {
    font-size: 1.2rem;
    color: var(--accent-color);
}

.ms-auto {
    margin-left: auto;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--bottom-bar-height);
    background-color: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
    transition: transform 0.3s ease;
}

.bottom-nav.hidden {
    transform: translateY(100%);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-color-secondary);
    font-size: 0.75rem;
    gap: 4px;
    width: 25%;
    transition: color 0.2s;
}

.nav-item i {
    font-size: 1.5rem;
}

.nav-item.active {
    color: var(--accent-color);
}

/* Home View Header */
.view-header {
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--blur-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Section Groups */
.section-group {
    padding: 20px;
    max-width: var(--content-max-width);
    margin: 0 auto;
    width: 100%;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
}

/* Hero Section */
.hero-section {
    padding: 40px 20px 20px;
    max-width: var(--content-max-width);
    margin: 0 auto;
    width: 100%;
}

.greeting {
    font-size: 2rem;
    line-height: 1.2;
    color: var(--text-color);
    font-weight: 800;
}

/* Recently Read Card */
.recently-read-card {
    background: var(--bg-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
    cursor: pointer;
    overflow: hidden;
    margin: 0 auto;
    width: 100%;
}

.recently-read-card:active {
    transform: scale(0.98);
}

.empty-recent {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-color-secondary);
    gap: 10px;
    opacity: 0.6;
}

.empty-recent i {
    font-size: 2.5rem;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.stat-card {
    background-color: var(--bg-color);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-color-secondary);
}

/* Recent Book Content Style */
.recent-book-ui {
    display: flex;
    gap: 20px;
    align-items: center;
}

.recent-cover {
    width: 80px;
    height: 110px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    object-fit: cover;
}

.recent-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.recent-title {
    font-size: 1.1rem;
    font-weight: 700;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.recent-progress {
    font-size: 0.85rem;
    color: var(--text-color-secondary);
}

.progress-bar-mini {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.progress-fill-mini {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
}

/* Onboarding View */
#onboarding-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    z-index: 10000;
    display: none;
    overflow-y: auto;
}

#onboarding-view.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.onboarding-container.notion-style {
    background: #ffffff;
    color: #37352f;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
    width: 100%;
    max-width: 480px;
    padding: 40px;
    display: flex;
    flex-direction: column;
}

.onboarding-step {
    display: none;
    width: 100%;
    animation: fadeInSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.onboarding-step.active {
    display: flex;
    flex-direction: column;
}

@keyframes fadeInSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.app-logo-notion {
    font-size: 3rem;
    margin-bottom: 2rem;
    color: #37352f;
    text-align: center;
}

.welcome-header {
    text-align: center;
}

.welcome-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.welcome-header p {
    font-size: 1.1rem;
    color: #73726e;
    line-height: 1.5;
    margin-bottom: 2rem;
}

.notion-features {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 2.5rem;
}

.notion-feat {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #37352f;
    font-size: 1rem;
}

.notion-feat i {
    color: #37352f;
    font-size: 1.2rem;
}

.notion-btn {
    width: 100%;
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid rgba(15, 15, 15, 0.1);
    background: #37352f;
    color: #fff;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.notion-btn:hover {
    background: #47453f;
}

.notion-btn.secondary {
    background: white;
    color: #37352f;
}

.notion-btn.secondary:hover {
    background: #f1f1f0;
}

.notion-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.notion-desc {
    color: #73726e;
    margin-bottom: 1.5rem;
}

.notion-terms-agree {
    margin-bottom: 2rem;
}

.notion-checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 30px;
    cursor: pointer;
    font-size: 0.95rem;
    user-select: none;
}

.notion-checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.notion-checkmark {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    height: 18px;
    width: 18px;
    background-color: white;
    border: 1.5px solid #37352f;
    border-radius: 3px;
}

.notion-checkbox-container:hover input~.notion-checkmark {
    background-color: #f1f1f0;
}

.notion-checkbox-container input:checked~.notion-checkmark {
    background-color: #37352f;
}

.notion-checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.notion-checkbox-container input:checked~.notion-checkmark:after {
    display: block;
}

.notion-checkbox-container .notion-checkmark:after {
    left: 5px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.side-by-side {
    display: flex;
    gap: 12px;
}

.notion-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.notion-small-gray {
    font-size: 0.85rem;
    color: #9b9a97;
    margin-top: 1.5rem;
    text-align: center;
}

/* --- Journal View Overhaul --- */
.journal-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    padding-bottom: 100px;
}

.journal-card {
    background: var(--bg-color);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.journal-card:active {
    transform: translateY(2px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.journal-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.journal-book-badge {
    background: rgba(var(--accent-color-rgb, 0, 0, 0), 0.05);
    color: var(--accent-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
}

.journal-date {
    font-size: 0.8rem;
    color: var(--text-color-secondary);
}

.journal-title {
    font-size: 1.3rem;
    font-weight: 800;
    margin-bottom: 12px;
    line-height: 1.3;
}

.journal-content {
    font-size: 1rem;
    color: var(--text-color);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-wrap;
}

.journal-footer {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
}

/* --- Reader UI & Touch Zones --- */
.reader-ui {
    z-index: 1500;
}

.touch-zone {
    position: absolute;
    top: 60px;
    /* Below top bar */
    bottom: 80px;
    /* Above bottom bar */
    z-index: 1000;
}

.touch-zone.left {
    left: 0;
    width: 25%;
}

.touch-zone.right {
    right: 0;
    width: 25%;
}

.touch-zone.center {
    left: 25%;
    right: 25%;
}

/* --- Viewer Settings Enhancements --- */
.settings-modal {
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    padding: 24px;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-modal.hidden {
    display: block !important;
    transform: translateY(100%);
}

.settings-group {
    margin-bottom: 24px;
}

.settings-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color-secondary);
    margin-bottom: 12px;
}

.mode-toggles,
.theme-toggles {
    display: flex;
    gap: 10px;
}

.mode-opt {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-opt.active {
    background: #37352f;
    color: white;
    border-color: #37352f;
}

.auto-flow-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.speed-control {
    flex: 1;
}

.speed-control input[type="range"] {
    width: 100%;
}

/* Color Overrides for Themes - REVERTED TO ORIGINAL */
[data-theme="light"] {
    --bg-color: #ffffff;
    --text-color: #111111;
    --card-bg: #ffffff;
}

[data-theme="sepia"] {
    --bg-color: #f6f1d1;
    --text-color: #5f4b32;
    --card-bg: rgba(95, 75, 50, 0.05);
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --card-bg: rgba(255, 255, 255, 0.05);
}

/* Sync Status UI */
.sync-status {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4cd964;
    /* Apple Switch Green */
    font-size: 1.2rem;
}

.sync-status.active {
    animation: sync-pulse 4s infinite ease-in-out;
}

.sync-status.syncing {
    animation: spin 1s infinite linear;
}

.sync-status.error {
    color: #ff3b30;
}

@keyframes sync-pulse {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

/* --- Modals & Overlays --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 5000;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

/* Custom Context Menu */
.context-menu {
    position: fixed;
    z-index: 6000;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    width: 180px;
    overflow: hidden;
    padding: 6px;
}

.context-menu .menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: background 0.2s;
    border: none;
}

.context-menu .menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.context-menu .menu-item.destructive {
    color: #ff3b30;
}

/* Bottom Modal (Mobile) */
.bottom-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--bg-color);
    border-radius: 24px 24px 0 0;
    z-index: 5500;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.bottom-modal.hidden {
    display: flex !important;
    transform: translateY(100%);
}

.modal-handle {
    width: 40px;
    height: 5px;
    background: var(--border-color);
    border-radius: 3px;
    margin: 12px auto;
}

.modal-header {
    padding: 0 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
}

.modal-body {
    padding: 0 20px 40px;
}

/* Journal Add Form */
.journal-modal {
    height: 85vh;
}

.journal-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 20px;
    color: var(--text-color);
    outline: none;
}

.journal-textarea {
    width: 100%;
    height: calc(100% - 60px);
    border: none;
    background: transparent;
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-color);
    outline: none;
    resize: none;
}

/* Floating Action Button */
.fab-btn {
    position: fixed;
    right: 20px;
    bottom: 100px;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background: var(--accent-color);
    color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transition: transform 0.2s;
}

.fab-btn:active {
    transform: scale(0.9);
}

.text-btn {
    font-weight: 600;
    font-size: 1rem;
    padding: 8px 16px;
    border-radius: 8px;
}

.sync-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px;
    background: rgba(var(--accent-color-rgb, 0, 0, 0), 0.05);
    border-radius: 12px;
}

.sync-card i {
    font-size: 2.2rem;
    color: var(--accent-color);
}

.sync-info h4 {
    font-size: 1rem;
    font-weight: 700;
}

.sync-info p {
    font-size: 0.8rem;
    color: var(--text-color-secondary);
}

.theme-preview {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin-bottom: 8px;
}

.theme-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: transparent;
    border: none;
    cursor: pointer;
}

.theme-opt span {
    font-size: 0.85rem;
    font-weight: 600;
}

/* Removed gradient to satisfy user request */
.reader-controls {
    background: var(--bg-color);
    box-shadow: none !important;
}

/* If user meant the settings modal shadow */
.settings-modal {
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.05);
    /* Lighter shadow */
}

/* Scroll mode fix: ensure no overflow hidden on container */
#viewer {
    background: var(--bg-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}