/* --- 1. BASIC SETUP --- */
body {
    margin: 0;
    padding: 0;
    background-color: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Noto Serif Tamil', serif;
    -webkit-font-smoothing: antialiased;
    /* Prevent 'pull-to-refresh' on mobile so swipe works cleanly */
    overscroll-behavior-y: none;
}

/* --- USER HEADER (top corner of page) --- */
.user-header {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 5;
}

.user-header.hidden {
    display: none;
}

.welcome-text {
    font-size: 10px;
    color: #8b7355;
    font-style: italic;
}

.header-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
    border: 1px solid #d4c4b0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #8b7355;
}

.icon-btn:hover {
    background-color: #8b7355;
    border-color: #8b7355;
    color: #fdfbf7;
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

/* --- READING NAV (Home & TOC buttons during reading - only when not logged in) --- */
.reading-nav {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 5;
}

/* Hide reading-nav when user-header is visible (logged in) */
.user-header:not(.hidden) ~ .reading-nav {
    display: none;
}

/* --- 2. THE PAGE STYLE --- */
.book-page {
    background-color: #fdfbf7;
    background-image: url("https://www.transparenttextures.com/patterns/cream-paper.png");

    width: min(480px, 100vw);
    height: 680px;

    padding: 50px 60px 60px 60px;
    box-sizing: border-box;
    box-shadow: 0 1px 1px rgba(0,0,0,0.15), 0 10px 0 -5px #eee, 0 10px 1px -4px rgba(0,0,0,0.15);

    display: flex;
    flex-direction: column;
    position: relative;
    margin-bottom: 0;
}


.hidden-page { display: none !important; }

/* --- 3. ON-PAGE NAVIGATION ARROWS --- */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px; /* Made slightly bigger for touch targets */
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #ccc;
    font-size: 24px;
    font-family: sans-serif;
    user-select: none;
    transition: all 0.2s ease;
    z-index: 10;
}

.nav-arrow:hover {
    color: #000;
    background-color: rgba(0,0,0,0.05);
    border-radius: 50%;
}

.nav-arrow.left { left: 0px; }
.nav-arrow.right { right: 0px; }

.nav-arrow.disabled { display: none; }

/* --- 4. HEADERS & TITLES --- */
h1.main-title {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: #000;
    margin-top: 20px;
    margin-bottom: 40px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.running-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 25px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 8px;
    flex-shrink: 0;
}

.header-story {
    font-size: 10px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.header-author {
    font-size: 10px;
    color: #888;
    font-style: italic;
}

/* --- 5. CONTENT --- */
.content-area {
    font-size: 14px;
    line-height: 2.2;
    color: #2b2b2b;
    text-align: justify;
    flex-grow: 1;
    overflow: hidden;
}

/* Allow scrolling for forms */
.content-area:has(.book-form),
.content-area:has(.books-dashboard) {
    overflow-y: auto;
}

/* --- 6. FOOTER --- */
.signature {
    text-align: right;
    font-size: 12px;
    color: #444;
    font-style: italic;
    margin-top: 20px;
    flex-shrink: 0;
}

.signature.book-signature {
    text-align: left;
    position: absolute;
    bottom: 60px;
    left: 60px;
}

.page-number {
    position: absolute;
    bottom: 20px;
    width: 100%;
    text-align: center;
    font-size: 10px;
    color: #999;
    left: 0;
}

/* --- PAGE WATERMARK (reading mode attribution) --- */
.page-watermark {
    position: absolute;
    bottom: 5px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 9px;
    color: #666;
    font-style: italic;
    pointer-events: none;
}

#raw-source { display: none; }

/* --- 7. LOGIN BUTTON --- */
.login-container {
    text-align: center;
    margin-top: 30px;
    flex-shrink: 0;
}

.login-btn {
    display: inline-block;
    padding: 12px 32px;
    font-family: 'Noto Serif Tamil', serif;
    font-size: 14px;
    font-weight: 600;
    color: #5c4a3d;
    background-color: transparent;
    border: 2px solid #8b7355;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 0.5px;
}

.login-btn:hover {
    background-color: #8b7355;
    color: #fdfbf7;
    box-shadow: 0 2px 8px rgba(92, 74, 61, 0.3);
}

.login-btn:active {
    transform: scale(0.98);
}

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-btn-secondary {
    background-color: transparent;
    border-color: #aaa;
    color: #666;
}

.login-btn-secondary:hover {
    background-color: #eee;
    color: #444;
    border-color: #888;
}

.login-btn-small {
    padding: 8px 16px;
    font-size: 12px;
}

.dashboard-header .login-btn {
    padding: 8px 16px;
    font-size: 12px;
}

/* --- 8. AUTH FORM --- */
.auth-container {
    margin-top: 25px;
    text-align: center;
}

.auth-form {
    text-align: center;
}

.auth-text {
    font-size: 13px;
    color: #555;
    margin-bottom: 15px;
    line-height: 1.6;
}

.auth-text strong {
    color: #333;
}

.auth-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-input {
    width: 100%;
    max-width: 240px;
    padding: 10px 14px;
    font-family: 'Noto Serif Tamil', serif;
    font-size: 14px;
    color: #333;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #8b7355;
    box-shadow: 0 0 0 2px rgba(139, 115, 85, 0.2);
}

.form-input::placeholder {
    color: #999;
}

/* Select dropdown styling */
select.form-input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b7355' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

select.form-input:focus {
    outline: none;
    border-color: #8b7355;
    box-shadow: 0 0 0 2px rgba(139, 115, 85, 0.2);
}

select.form-input option {
    font-family: 'Noto Serif Tamil', serif;
    padding: 8px;
    background-color: #fdfbf7;
    color: #333;
}

/* Author option radio buttons */
.author-option {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
}

.radio-label input[type="radio"] {
    accent-color: #8b7355;
    cursor: pointer;
}

.form-input-code {
    text-align: center;
    font-size: 18px;
    letter-spacing: 4px;
    font-family: monospace;
}

.form-error {
    color: #c53030;
    font-size: 12px;
    margin-top: 8px;
    margin-bottom: 8px;
}

.form-hint {
    color: #8b7355;
    font-size: 11px;
    margin-top: 4px;
    font-style: italic;
}

.char-count {
    color: #8b7355;
    font-size: 11px;
    margin-top: 4px;
    text-align: right;
}

.char-count.over-limit {
    color: #c53030;
    font-weight: bold;
}

.hidden {
    display: none !important;
}

/* --- 9. TOAST NOTIFICATIONS --- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: #fdfbf7;
    border: 1px solid #d4c4b0;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: 'Noto Serif Tamil', serif;
    font-size: 13px;
    color: #333;
    min-width: 250px;
    max-width: 350px;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

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

.toast-success {
    border-left: 4px solid #38a169;
}

.toast-error {
    border-left: 4px solid #c53030;
}

.toast-info {
    border-left: 4px solid #8b7355;
}

.toast-message {
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    margin-left: 10px;
    line-height: 1;
}

.toast-close:hover {
    color: #333;
}

/* --- 10. BOOKS DASHBOARD --- */
.books-dashboard {
    text-align: left;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.dashboard-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.books-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.book-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 12px 15px;
    background-color: transparent;
    border: 1px solid #d4c4b0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.book-item:hover {
    background-color: #f5f0e8;
    border-color: #8b7355;
}

.book-title {
    font-family: 'Noto Serif Tamil', serif;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.book-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.book-type {
    font-size: 10px;
    color: #8b7355;
    background-color: #f5f0e8;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: capitalize;
}

.book-author {
    font-size: 11px;
    color: #888;
    font-style: italic;
}

.books-pagination {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 15px;
}

.loading {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 20px;
}

.empty-message {
    text-align: center;
    padding: 30px 20px;
}

.empty-message p {
    color: #666;
    margin-bottom: 15px;
}

.error-message {
    text-align: center;
    color: #c53030;
    padding: 20px;
}

/* --- 11. BOOK FORM --- */
.book-form {
    text-align: left;
}

.form-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}

.book-form .form-group {
    margin-bottom: 15px;
}

.book-form .form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    margin-bottom: 5px;
}

.book-form .form-input {
    width: 100%;
    max-width: none;
}

.form-textarea {
    width: 100%;
    padding: 10px 14px;
    font-family: 'Noto Serif Tamil', serif;
    font-size: 14px;
    color: #333;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    resize: vertical;
    min-height: 120px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-textarea:focus {
    outline: none;
    border-color: #8b7355;
    box-shadow: 0 0 0 2px rgba(139, 115, 85, 0.2);
}

.form-textarea::placeholder {
    color: #999;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* --- 12. BOOK VIEW --- */
.book-view {
    text-align: left;
}

.book-view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.book-view-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0;
    flex: 1;
}

.book-view-actions {
    display: flex;
    gap: 6px;
}

.book-view-content {
    font-size: 14px;
    line-height: 2;
    color: #2b2b2b;
    text-align: justify;
}

.book-view-footer {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.book-view-author {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.book-view-nav {
    margin-top: 20px;
}

/* Edit controls for book creator */
.book-edit-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

/* --- 13. BOOK TOC --- */
.book-toc {
    text-align: left;
}

.toc-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.toc-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.toc-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.toc-actions {
    display: flex;
    gap: 6px;
}

.toc-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.toc-author {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.toc-section-title {
    font-size: 12px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0 0 10px 0;
}

.toc-chapters {
    margin-bottom: 20px;
}

.chapters-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.chapter-number {
    font-size: 12px;
    color: #888;
    min-width: 24px;
}

.chapter-title-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0;
    font-family: 'Noto Serif Tamil', serif;
    font-size: 14px;
    color: #333;
    text-align: left;
    cursor: pointer;
    transition: color 0.2s;
}

.chapter-title-btn:hover {
    color: #8b7355;
}

.chapter-actions {
    display: flex;
    gap: 4px;
}

.icon-btn-sm {
    width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: transparent;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    color: #888;
    transition: all 0.2s ease;
}

.icon-btn-sm:hover {
    background-color: #f5f0e8;
    border-color: #8b7355;
    color: #8b7355;
}

.toc-nav {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

/* --- 14. CHAPTER FOOTER --- */
.chapter-footer {
    margin-top: 20px;
}

.chapter-footer .book-signature {
    position: relative;
    bottom: auto;
    left: auto;
    margin-bottom: 15px;
}

.chapter-nav {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.book-chapters {
    font-size: 10px;
    color: #666;
}

/* --- 15. CONSENT CHECKBOX --- */
.consent-group {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 12px;
    color: #555;
    cursor: pointer;
    line-height: 1.5;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
    accent-color: #8b7355;
    cursor: pointer;
    flex-shrink: 0;
}

/* --- 16. PROFILE FORM --- */
.profile-title {
    font-size: 16px;
    color: #5c4a3d;
    margin-bottom: 10px;
    text-align: center;
}

/* --- 17. CUSTOM CONFIRM DIALOG --- */
.confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.confirm-dialog {
    background: #f5f0e8;
    border-radius: 8px;
    padding: 25px 30px;
    max-width: 350px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.confirm-message {
    font-size: 14px;
    color: #333;
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-delete-btn {
    background-color: #c9302c !important;
    border-color: #c9302c !important;
    color: #fff !important;
}

.confirm-delete-btn:hover {
    background-color: #a02622 !important;
}

.checkbox-label span {
    flex: 1;
}

/* --- 18. LOVE BUTTON --- */
.love-btn {
    display: flex;
    align-items: center;
    gap: 4px;
}

.love-btn svg {
    transition: fill 0.2s ease, transform 0.2s ease;
}

.love-btn.loved svg {
    fill: #e74c3c;
}

.love-btn:hover svg {
    transform: scale(1.1);
}

.love-btn.loved:hover svg {
    fill: #c0392b;
}

.love-count {
    font-size: 11px;
    color: #666;
}

.love-btn.loved .love-count {
    color: #e74c3c;
}

/* Love count in book list */
.book-loves {
    font-size: 10px;
    color: #e74c3c;
}
