/* --- GLOBAL & TYPOGRAPHY --- */
:root {
    --reader-font-family: 'Merriweather', serif;
    --reader-font-size: 20px;
    
    /* RGB values for transparency effects */
    --mauve-rgb: 198, 160, 246;
    --blue-rgb: 138, 173, 244;
    --teal-rgb: 139, 213, 202;
    --text-rgb: 202, 211, 245;
    --surface0-rgb: 54, 58, 79;
    --surface1-rgb: 73, 77, 100;
    --mantle-rgb: 30, 32, 48;
    --base-rgb: 36, 39, 58;
}

html {
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    scroll-padding-top: 5rem;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: 
        radial-gradient(circle at 20% 80%, rgba(var(--mauve-rgb), 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(var(--blue-rgb), 0.05) 0%, transparent 50%),
        var(--base);
    background-attachment: fixed;
    color: var(--text);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1.6;
    font-size: 16px;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--mauve) var(--surface0);
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 30% 40%, rgba(var(--teal-rgb), 0.03) 0%, transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(var(--mauve-rgb), 0.02) 0%, transparent 40%);
    animation: backgroundShift 20s ease-in-out infinite;
    z-index: -1;
    pointer-events: none;
}

@keyframes backgroundShift {
    0%, 100% { transform: translateX(0%) translateY(0%); }
    25% { transform: translateX(1%) translateY(-1%); }
    50% { transform: translateX(-1%) translateY(1%); }
    75% { transform: translateX(1%) translateY(1%); }
}
body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
body::-webkit-scrollbar-track {
    background: var(--surface0);
    border-radius: 10px;
}
body::-webkit-scrollbar-thumb {
    background-color: var(--mauve);
    border-radius: 10px;
    border: 2px solid var(--surface0);
    transition: background-color 0.2s ease-in-out;
}
body::-webkit-scrollbar-thumb:hover {
    background-color: var(--pink);
}
body::-webkit-scrollbar-thumb:active {
    background-color: var(--flamingo);
}
body.modal-open {
    overflow: hidden;
}
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
a {
    text-decoration: none;
    color: inherit;
}

/* --- HEADER --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(var(--mantle-rgb), 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(var(--surface0-rgb), 0.3);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.logo {
    position: relative;
}
.logo-link {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--lavender);
    position: relative;
    z-index: 1;
    transition: color 0.3s ease;
}
.logo-decorator {
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background-color: var(--mauve);
    border-radius: 8px;
    opacity: 0.2;
    z-index: 0;
    transition: all 0.3s ease;
}
.logo:hover .logo-decorator {
    transform: translateY(-50%) rotate(45deg);
    opacity: 0.3;
}
.header-actions-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.header-action-icon-button {
    background: linear-gradient(135deg, rgba(var(--surface0-rgb), 0.8), rgba(var(--surface1-rgb), 0.6));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    color: var(--text);
    font-size: 1.2rem;
    padding: 0.4rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.header-action-icon-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.header-action-icon-button:hover {
    background: linear-gradient(135deg, rgba(var(--mauve-rgb), 0.2), rgba(var(--blue-rgb), 0.2));
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 20px rgba(var(--mauve-rgb), 0.3);
    color: var(--mauve);
}

.header-action-icon-button:hover::before {
    left: 100%;
}

.header-action-icon-button:focus-visible {
    outline: 2px solid var(--mauve);
    outline-offset: 2px;
    transform: translateY(-2px) scale(1.05);
}

/* --- THEME TOGGLE --- */
.theme-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    background-color: var(--surface0);
    transition: background-color 0.3s ease, transform 0.3s ease;
}
.theme-toggle:hover {
    background-color: var(--surface1);
    transform: rotate(15deg);
}
.sun-icon, .moon-icon {
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}
.sun-icon i { color: var(--yellow); }
.moon-icon i { color: var(--lavender); }

/* --- MAIN CONTENT & VIEWS --- */
main {
    flex: 1;
    padding: 2rem;
}
.view {
    display: none;
    animation: fadeInView 0.4s ease-out forwards;
}
.view.active {
    display: block;
}

/* --- LIBRARY VIEW --- */
.book-library-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--surface0);
}
.book-library-header h2 {
    margin: 0;
    color: var(--text);
    font-weight: 600;
    font-size: 1.75rem;
}
.add-book-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--mauve), var(--blue));
    color: var(--base);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(var(--mauve-rgb), 0.3);
    position: relative;
    overflow: hidden;
}

.add-book-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.add-book-btn:hover {
    background: linear-gradient(135deg, var(--pink), var(--mauve));
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(var(--mauve-rgb), 0.4);
}

.add-book-btn:hover::before {
    left: 100%;
}
.storage-usage {
    margin-bottom: 1.5rem;
}
.storage-bar-container {
    height: 8px;
    background-color: var(--surface0);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.storage-bar {
    height: 100%;
    background-color: var(--blue);
    width: 0%;
    transition: width 0.5s ease-out, background-color 0.3s;
    border-radius: 4px;
}
.storage-text {
    font-size: 0.8rem;
    color: var(--subtext0);
    text-align: right;
    margin: 0;
}
.books-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

/* Stagger animation for book cards */
.book-card {
    animation: fadeInStagger 0.6s ease-out forwards;
    opacity: 0;
    transform: translateY(20px);
}

.book-card:nth-child(1) { animation-delay: 0.1s; }
.book-card:nth-child(2) { animation-delay: 0.2s; }
.book-card:nth-child(3) { animation-delay: 0.3s; }
.book-card:nth-child(4) { animation-delay: 0.4s; }
.book-card:nth-child(5) { animation-delay: 0.5s; }
.book-card:nth-child(6) { animation-delay: 0.6s; }
.book-card:nth-child(n+7) { animation-delay: 0.7s; }

@keyframes fadeInStagger {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.empty-library-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--overlay1);
    font-style: italic;
    background-color: var(--surface0);
    border-radius: 8px;
}
.book-card {
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(135deg, 
        rgba(var(--mantle-rgb), 0.9), 
        rgba(var(--surface0-rgb), 0.8)
    );
    backdrop-filter: blur(20px);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    height: 100%;
    cursor: pointer;
    position: relative;
}

.book-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(var(--mauve-rgb), 0.1), 
        rgba(var(--blue-rgb), 0.05),
        rgba(var(--teal-rgb), 0.1)
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 1;
    pointer-events: none;
}

.book-card:hover {
    transform: translateY(-12px) rotateX(5deg) scale(1.02);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.2),
        0 8px 16px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(var(--mauve-rgb), 0.2);
}

.book-card:hover::before {
    opacity: 1;
}
.book-cover {
    width: 100%;
    height: 260px;
    background-color: var(--surface1);
    object-fit: cover;
    border-bottom: 1px solid var(--surface1);
}
.book-info {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.book-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    height: 2.8em;
}
.book-author {
    font-size: 0.8rem;
    color: var(--subtext0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: auto;
}

/* --- READER VIEW --- */
.reader-header {
    position: sticky;
    top: 60px;
    background-color: var(--mantle);
    padding: 0.75rem 0;
    margin-bottom: 1.5rem;
    z-index: 800;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}
.reader-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    margin-bottom: 0.75rem;
}
.back-button {
    padding: 0.5rem 1rem;
    background-color: var(--surface1);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.back-button:hover {
    background-color: var(--surface2);
    transform: translateY(-1px);
}
.reading-stats {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}
.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
}
.stat-label {
    font-size: 0.7rem;
    color: var(--subtext0);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}
.stat-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--mauve);
}
.progress-container {
    height: 5px;
    background-color: var(--surface0);
    overflow: hidden;
    border-radius: 2.5px;
}
.progress-bar {
    height: 100%;
    background-color: var(--mauve);
    width: 0%;
    transition: width 0.3s ease-out;
    border-radius: 2.5px;
}
.typing-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    background: linear-gradient(135deg, 
        rgba(var(--mantle-rgb), 0.95), 
        rgba(var(--surface0-rgb), 0.85)
    );
    backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    position: relative;
}

.typing-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(var(--blue-rgb), 0.03), 
        rgba(var(--mauve-rgb), 0.02),
        rgba(var(--teal-rgb), 0.03)
    );
    border-radius: 16px;
    z-index: -1;
    pointer-events: none;
}
.book-title-reader, .chapter-title-reader {
    font-family: 'Merriweather', Georgia, serif;
    text-align: center;
}
.book-title-reader {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
}
.chapter-title-reader {
    font-size: 1.1rem;
    color: var(--subtext1);
    margin-bottom: 1.5rem;
    font-weight: 500;
}
.typing-text {
    font-family: var(--reader-font-family);
    font-size: var(--reader-font-size);
    line-height: 1.8;
    margin-bottom: 1rem;
    white-space: pre-wrap;
    text-align: justify;
    hyphens: auto;
    color: var(--text);
    outline: none;
    cursor:none;
    min-height: 100px;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    overflow-wrap: break-word;
}
.char {
    display: inline-block;
    position: relative;
    transition: color 0.1s, background-color 0.1s;
    vertical-align: bottom;
}
.char.correct { color: var(--green); }
.char.incorrect {
    color: var(--red);
    background-color: rgba(var(--red-rgb), 0.1);
    text-decoration: underline wavy rgba(var(--red-rgb), 0.5);
    animation: shakeChar 0.1s ease-in-out;
}
.char.current::after {
    content: '';
    position: absolute;
    bottom: 0px;
    left: 0px;
    width: 1.5px;
    height: 1.3em;
    background-color: var(--mauve);
    animation: blinkCursor 1s infinite;
    z-index: 1;
    border-radius: 1px;
}
.char.untyped { color: var(--overlay1); }
.char.space { position: relative; }
.char.space::after {
    content: '·';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    color: var(--overlay1);
    pointer-events: none;
    font-size: 1em;
}
.char.space.correct::after { color: var(--green); opacity: 0.5; }
.char.space.incorrect::after { color: var(--red); opacity: 0.6; }
.typing-instructions {
    font-size: 0.8rem;
    color: var(--subtext0);
    text-align: center;
    margin-top: 1rem;
}

/* --- BOOK DETAILS VIEW --- */
#book-details-view {
    padding: 1rem 2rem;
}
.book-details-container {
    max-width: 900px;
    margin: 0 auto;
    background-color: var(--mantle);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    position: relative;
}
.details-back-button {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
}
.details-content {
    display: flex;
    gap: 2.5rem;
    margin-top: 3rem;
}
.details-cover-container {
    flex-shrink: 0;
    width: 220px;
}
.details-book-cover {
    width: 100%;
    height: auto;
    max-height: 330px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 6px 15px rgba(0,0,0,0.2);
    background-color: var(--surface0);
}
.details-info-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.details-book-title-heading {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 0;
    margin-bottom: 0.35rem;
    font-family: 'Merriweather', serif;
}
.details-book-author {
    font-size: 1.1rem;
    color: var(--subtext0);
    margin-bottom: 1.5rem;
    font-style: italic;
}
.details-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
    padding: 1rem 0;
    border-top: 1px solid var(--surface1);
    border-bottom: 1px solid var(--surface1);
}
.details-stat-item {
    text-align: center;
    padding: 0.75rem 0.5rem;
    background-color: var(--surface0);
    border-radius: 6px;
}
.details-actions {
    margin-top: auto;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.action-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.action-btn.primary-action {
    background: linear-gradient(135deg, var(--mauve), var(--blue));
    color: var(--base);
    box-shadow: 0 4px 12px rgba(var(--mauve-rgb), 0.3);
}

.action-btn.primary-action:hover {
    background: linear-gradient(135deg, var(--pink), var(--mauve));
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(var(--mauve-rgb), 0.4);
}

.action-btn.secondary-action {
    background: linear-gradient(135deg, rgba(var(--surface0-rgb), 0.8), rgba(var(--surface1-rgb), 0.6));
    backdrop-filter: blur(10px);
    color: var(--text);
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.action-btn.secondary-action:hover {
    background: linear-gradient(135deg, rgba(var(--surface1-rgb), 0.9), rgba(var(--surface2), 0.7));
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.action-btn.danger-action {
    background: linear-gradient(135deg, var(--red), var(--maroon));
    color: var(--base);
    box-shadow: 0 4px 12px rgba(var(--red-rgb), 0.3);
}

.action-btn.danger-action:hover {
    background: linear-gradient(135deg, var(--maroon), var(--red));
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 20px rgba(var(--red-rgb), 0.4);
}

.action-btn:hover::before {
    left: 100%;
}

/* --- SETTINGS VIEW --- */
#settings-view {
    padding: 0;
}
.settings-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    height: calc(100vh - 60px);
    background-color: var(--base);
    overflow: hidden;
}
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--mantle);
    border-bottom: 1px solid var(--surface0);
    flex-shrink: 0;
}
.settings-header h2 {
    margin: 0;
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    flex-grow: 1;
}
.settings-header .back-button {
    flex-shrink: 0;
}
.settings-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.settings-header .action-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}
.settings-header .action-btn.primary-action:hover {
    box-shadow: 0 2px 4px rgba(var(--pink-rgb, 234, 118, 203), 0.3);
}
.settings-content-area {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    min-height: 0;
}
.settings-controls {
    flex: 1;
    padding: 1.5rem;
    background-color: var(--mantle);
    overflow-y: auto;
    border-right: 1px solid var(--surface0);
    min-width: 300px;
    max-width: 450px;
}
.settings-preview-area {
    flex: 1.5;
    background-color: var(--base);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
}
.preview-wrapper {
    padding: 1.5rem;
    overflow-y: auto;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--surface1);
}
.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.settings-section h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--mauve);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}
.settings-section h3 i {
    margin-right: 0.5rem;
    font-size: 1rem;
}
.settings-section-description {
    font-size: 0.85rem;
    color: var(--subtext0);
    margin-bottom: 1rem;
    line-height: 1.5;
}
.settings-action-buttons-column {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.settings-action-buttons-column .action-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
}
.settings-action-buttons-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}
.settings-action-buttons-grid .action-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    text-align: left;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--subtext0);
    margin-bottom: 0.4rem;
    font-weight: 500;
}
.form-group select,
.form-group input[type="url"],
.form-group input[type="range"] {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--surface2);
    background-color: var(--surface0);
    color: var(--text);
    border-radius: 5px;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input[type="color"] {
    width: 100%;
    height: 38px;
    padding: 0.2rem;
    border: 1px solid var(--surface2);
    background-color: var(--surface0);
    border-radius: 5px;
    cursor: pointer;
}
.form-group select:focus,
.form-group input[type="url"]:focus,
.form-group input[type="range"]:focus,
.form-group input[type="color"]:focus {
    outline: none;
    border-color: var(--mauve);
    box-shadow: 0 0 0 2px rgba(var(--mauve-rgb, 198, 160, 246), 0.3);
}
#font-size-value {
    font-weight: bold;
    color: var(--mauve);
}
.preview-header {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--surface1);
    flex-shrink: 0;
}
.preview-header h4 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--subtext1);
    font-weight: 500;
}
.typing-text-preview {
    font-family: var(--preview-font-family, 'Inter', sans-serif);
    font-size: var(--preview-font-size, 16px);
    line-height: 1.5;
    background-color: var(--preview-bg-color, var(--base));
    color: var(--preview-text-color, var(--text));
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--preview-surface-color, var(--surface1));
    margin-bottom: 1.5rem;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s, font-family 0.3s, font-size 0.3s;
    white-space: pre-wrap;
    text-align: justify;
    hyphens: auto;
}
.typing-text-preview h5 {
    font-family: inherit;
    font-size: calc(var(--preview-font-size, 16px) * 1.2);
    font-weight: bold;
    margin-bottom: 0.25rem;
    color: inherit;
}
.typing-text-preview h6 {
    font-family: inherit;
    font-size: calc(var(--preview-font-size, 16px) * 0.9);
    font-style: italic;
    margin-bottom: 1rem;
    color: var(--preview-subtext-color, var(--subtext0));
}
.typing-text-preview p {
    font-family: inherit;
    font-size: inherit;
    margin-bottom: 0.75rem;
}
.preview-char-styles {
    margin-top: 1rem;
    font-size: calc(var(--preview-font-size, 16px) * 0.9);
    opacity: 0.8;
    display: flex;
}
.char-style-label { margin-right: 0.5em; color: var(--preview-subtext-color, var(--subtext0)); }
.char-preview { display: inline-block; padding: 0.1em 0.3em; margin: 0 0.1em; border-radius: 3px; }
.char-preview.correct { background-color: rgba(var(--green-rgb, 166, 218, 149), 0.2); color: var(--green, #a6da95); }
.char-preview.incorrect { background-color: rgba(var(--red-rgb, 237, 135, 150), 0.2); color: var(--red, #ed8796); text-decoration: underline; }
.char-preview.untyped { color: var(--overlay1, #8087a2); }
.char-preview.current { background-color: var(--preview-primary-accent-color, var(--mauve, #c6a0f6)); color: var(--base, #24273a); animation: blinkCursor 1s infinite; }
.preview-ui-elements { margin-top: 1rem; flex-shrink: 0; }
.preview-ui-elements button { padding: 0.6rem 1.2rem; border: none; border-radius: 6px; font-size: 0.9rem; font-weight: 500; margin-right: 0.5rem; margin-bottom: 0.5rem; cursor: default; transition: background-color 0.3s, color 0.3s, border-color 0.3s; }
.preview-button-primary { background-color: var(--preview-primary-accent-color, var(--mauve)); color: var(--preview-primary-accent-text-color, var(--base)); }
.preview-button-secondary { background-color: var(--preview-surface-color, var(--surface1)); color: var(--preview-text-color, var(--text)); border: 1px solid var(--preview-secondary-accent-color, var(--surface2)); }
.preview-card { background-color: var(--preview-surface-color, var(--surface0)); color: var(--preview-text-color, var(--text)); padding: 1rem; border-radius: 8px; margin-top: 1rem; border: 1px solid var(--preview-surface-color, var(--surface1)); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }

/* --- STATIC PAGE CONTAINER --- */
.static-page-container {
    max-width: 900px;
    margin: 0 auto;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    background-color: var(--base);
    overflow: hidden;
}
.static-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background-color: var(--mantle);
    border-bottom: 1px solid var(--surface0);
    flex-shrink: 0;
}
.static-page-header h2 {
    margin: 0;
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    flex-grow: 1;
}
.static-page-header .back-button {
    flex-shrink: 0;
}
.static-page-header-spacer {
    width: 80px;
    flex-shrink: 0;
}
.static-page-content-area {
    padding: 1.5rem 2rem;
    overflow-y: auto;
    flex-grow: 1;
    background-color: var(--mantle);
}

/* --- ABOUT VIEW SPECIFIC STYLES --- */
.donate-section {
    margin-bottom: 2.5rem;
    display: flex;
    justify-content: center;
}

.donate-card {
    background: linear-gradient(135deg, 
        rgba(var(--mantle-rgb), 0.95), 
        rgba(var(--surface0-rgb), 0.85)
    );
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    max-width: 400px;
    width: 100%;
}

.donate-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(var(--pink-rgb), 0.1), 
        rgba(var(--mauve-rgb), 0.05),
        rgba(var(--blue-rgb), 0.1)
    );
    border-radius: 16px;
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: -1;
    pointer-events: none;
}

.donate-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 
        0 15px 40px rgba(0, 0, 0, 0.15),
        0 5px 15px rgba(0, 0, 0, 0.1);
}

.donate-card:hover::before {
    opacity: 1;
}

.donate-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pink), var(--mauve));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    color: var(--base);
    font-size: 1.5rem;
    box-shadow: 0 4px 15px rgba(var(--pink-rgb), 0.3);
    animation: pulseGlow 3s ease-in-out infinite;
}

.donate-card h3 {
    font-size: 1.4rem;
    color: var(--text);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.donate-card p {
    color: var(--subtext0);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

.donate-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--pink), var(--mauve));
    color: var(--base);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(var(--pink-rgb), 0.3);
    position: relative;
    overflow: hidden;
}

.donate-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.donate-btn:hover {
    background: linear-gradient(135deg, var(--mauve), var(--pink));
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 20px rgba(var(--pink-rgb), 0.4);
    text-decoration: none;
    color: var(--base);
}

.donate-btn:hover::before {
    left: 100%;
}

.about-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--surface1);
}
.about-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.about-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--mauve);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
}
.about-section h3 i {
    margin-right: 0.6rem;
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}
.about-section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--peach);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
}
.about-section h4 i {
    margin-right: 0.5rem;
}
.about-section p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--subtext0);
    margin-bottom: 0.75rem;
}
.about-section p strong {
    color: var(--text);
    font-weight: 600;
}
.about-section a {
    color: var(--blue);
    text-decoration: none;
    font-weight: 500;
}
.about-section a:hover {
    text-decoration: underline;
    color: var(--sapphire);
}
#app-version {
    font-weight: bold;
    color: var(--text);
}

/* --- UNIFIED MODAL --- */
.unified-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(var(--base-rgb), 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    display: flex;
    transition: opacity 0.3s ease-in-out;
}
.unified-modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.unified-modal-overlay.show .unified-modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease-out;
}
.unified-modal-overlay.hiding {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}
.unified-modal-overlay.hiding .unified-modal-content {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    transition: transform 0.25s ease-in, opacity 0.2s ease-in;
}
.unified-modal-content {
    background: linear-gradient(135deg, 
        rgba(var(--mantle-rgb), 0.95), 
        rgba(var(--surface0-rgb), 0.9)
    );
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-radius: 16px;
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.3),
        0 10px 25px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 650px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    overflow: hidden;
    transform: translateY(-20px) scale(0.98);
    opacity: 0;
    position: relative;
}

.unified-modal-content::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(var(--mauve-rgb), 0.05), 
        rgba(var(--blue-rgb), 0.03),
        rgba(var(--teal-rgb), 0.05)
    );
    border-radius: 16px;
    z-index: -1;
    pointer-events: none;
}
.unified-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--surface0);
    background-color: var(--crust);
    flex-shrink: 0;
}
.unified-modal-title-heading {
    margin: 0;
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.unified-modal-title-heading i { color: var(--mauve); }
.unified-modal-close-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--subtext0);
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}
.unified-modal-close-btn:hover {
    color: var(--text);
    background-color: var(--surface0);
}
.unified-modal-body {
    padding: 1.5rem;
    flex-grow: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.unified-modal-body .drop-zone {
    margin: 0;
    border-width: 2px;
    border-radius: 10px;
    background-color: var(--surface0);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    flex-grow: 1;
}
.unified-modal-actions {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--surface0);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background-color: var(--crust);
    flex-shrink: 0;
}
.modal-action-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s, transform 0.1s;
}
.modal-action-btn.primary {
    background-color: var(--mauve);
    color: var(--base);
}
.modal-action-btn.primary:hover:not([disabled]) {
    background-color: var(--pink);
    transform: translateY(-1px);
}
.modal-action-btn.secondary {
    background-color: var(--surface1);
    color: var(--text);
}
.modal-action-btn.secondary:hover:not([disabled]) {
    background-color: var(--surface2);
}
.modal-action-btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
.unified-modal-body .chapter-selection-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
    min-height: 0;
}
.unified-modal-body .selection-instruction {
    text-align: center;
    color: var(--subtext0);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}
.unified-modal-body .chapter-selection-main {
    display: flex;
    gap: 1.5rem;
    flex-grow: 1;
    overflow: hidden;
    min-height: 0;
}
.unified-modal-body .chapters-list-container {
    flex: 0 0 40%;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.unified-modal-body .chapters-list {
    flex-grow: 1;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--surface1);
    background-color: var(--surface0);
    padding: 0.25rem;
}
.unified-modal-body .chapter-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    border: 1px solid var(--surface1);
    padding: 1.25rem;
    background-color: var(--base);
    overflow-y: auto;
    font-family: 'Merriweather', Georgia, serif;
}
.unified-modal-body .chapter-item {
    padding: 0.8rem 1rem;
    border-bottom: 1px solid var(--surface1);
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    color: var(--text);
}
.unified-modal-body .chapter-item:last-child { border-bottom: none; }
.unified-modal-body .chapter-item:hover { background-color: var(--surface1); }
.unified-modal-body .chapter-item.selected {
    background-color: var(--surface2) !important;
    color: var(--text);
}
.unified-modal-body .chapter-item.active { border-left: 4px solid var(--mauve); padding-left: calc(1rem - 4px); }
.unified-modal-body .chapter-title { font-weight: 600; margin-bottom: 0.25rem; }
.unified-modal-body .chapter-info { font-size: 0.75rem; color: var(--subtext0); }
.unified-modal-body .chapter-badge {
    position: absolute; top: 0.8rem; right: 1rem;
    background-color: var(--mauve); color: var(--base);
    font-size: 0.65rem; padding: 0.2rem 0.4rem; border-radius: 4px; font-weight: 500;
}
.unified-modal-body .chapter-preview-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--overlay0); text-align: center; padding: 1rem;
    min-height: 150px;
}
.unified-modal-body .chapter-preview-empty i { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.5; }
.unified-modal-body .chapter-preview-title {
    font-size: 1.15rem; font-weight: 600; margin-bottom: 1rem;
    color: var(--mauve); border-bottom: 1px solid var(--surface1); padding-bottom: 0.5rem;
    flex-shrink: 0;
}
.unified-modal-body .chapter-preview-content {
    font-size: 0.9rem; line-height: 1.7; color: var(--text);
    flex-grow: 1;
}
.unified-modal-body .chapter-preview-paragraph { margin-bottom: 0.8rem; text-indent: 1.5em; }

/* --- UTILITY & ANIMATIONS --- */
.timer-blinking { animation: blinkTimer 1s infinite; }
.paragraph-transition { animation: fadeInParagraph 0.5s ease-out; }
.typing-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--surface1);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1100;
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
}
.typing-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.typing-notification.error {
    background-color: var(--red);
    color: var(--base);
}
.typing-notification.success {
    background-color: var(--green);
    color: var(--base);
}
.settings-notification {
    position: fixed;
    bottom: -70px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background-color: var(--surface1);
    color: var(--text);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease-out, bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 0.9rem;
    border-top: 3px solid var(--green);
}
.settings-notification.show {
    opacity: 1;
    bottom: 20px;
}
.settings-notification.error {
    border-top-color: var(--red);
}
.completion-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(var(--base-rgb), 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    animation: fadeInView 0.5s ease-out;
}
.completion-content {
    background-color: var(--mantle);
    border-radius: 16px;
    padding: 2.5rem 3rem;
    width: 90%;
    max-width: 550px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    animation: bounceInModal 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}
.completion-content h2 {
    color: var(--green);
    font-size: 2.2rem;
    margin-bottom: 1rem;
}
.completion-content p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    color: var(--text);
}
.completion-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 2.5rem;
}
.completion-stat .value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--mauve);
}
.completion-stat .label {
    font-size: 0.85rem;
    color: var(--subtext0);
    margin-top: 0.5rem;
}
.completion-button {
    padding: 0.9rem 2.2rem;
    background-color: var(--green);
    color: var(--base);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.15s;
}
.completion-button:hover {
    background-color: var(--teal);
    transform: translateY(-2px);
}

/* --- CUSTOM SCROLLBARS FOR SPECIFIC ELEMENTS --- */
.settings-controls,
.settings-preview-area .preview-wrapper,
.static-page-content-area,
.unified-modal-body .chapters-list,
.unified-modal-body .chapter-preview {
    scrollbar-width: thin;
    scrollbar-color: var(--mauve) var(--surface0);
}
.settings-controls::-webkit-scrollbar,
.settings-preview-area .preview-wrapper::-webkit-scrollbar,
.static-page-content-area::-webkit-scrollbar,
.unified-modal-body .chapters-list::-webkit-scrollbar,
.unified-modal-body .chapter-preview::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.settings-controls::-webkit-scrollbar-track,
.settings-preview-area .preview-wrapper::-webkit-scrollbar-track,
.static-page-content-area::-webkit-scrollbar-track,
.unified-modal-body .chapters-list::-webkit-scrollbar-track,
.unified-modal-body .chapter-preview::-webkit-scrollbar-track {
    background: var(--surface0);
    border-radius: 10px;
}
.settings-controls::-webkit-scrollbar-thumb,
.settings-preview-area .preview-wrapper::-webkit-scrollbar-thumb,
.static-page-content-area::-webkit-scrollbar-thumb,
.unified-modal-body .chapters-list::-webkit-scrollbar-thumb,
.unified-modal-body .chapter-preview::-webkit-scrollbar-thumb {
    background-color: var(--mauve);
    border-radius: 10px;
    border: 2px solid var(--surface0);
}
.settings-controls::-webkit-scrollbar-thumb:hover,
.settings-preview-area .preview-wrapper::-webkit-scrollbar-thumb:hover,
.static-page-content-area::-webkit-scrollbar-thumb:hover,
.unified-modal-body .chapters-list::-webkit-scrollbar-thumb:hover,
.unified-modal-body .chapter-preview::-webkit-scrollbar-thumb:hover {
    background-color: var(--pink);
}
.settings-controls::-webkit-scrollbar-thumb:active,
.settings-preview-area .preview-wrapper::-webkit-scrollbar-thumb:active,
.static-page-content-area::-webkit-scrollbar-thumb:active,
.unified-modal-body .chapters-list::-webkit-scrollbar-thumb:active,
.unified-modal-body .chapter-preview::-webkit-scrollbar-thumb:active {
    background-color: var(--flamingo);
}

/* --- KEYFRAME ANIMATIONS --- */
@keyframes fadeInView {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes blinkCursor { 50% { opacity: 0; } }

@keyframes shakeChar {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-1px); }
    75% { transform: translateX(1px); }
}

@keyframes bounceInModal {
    0% { transform: scale(0.8) translateY(20px); opacity: 0; }
    70% { transform: scale(1.03) translateY(0); opacity: 1; }
    100% { transform: scale(1) translateY(0); }
}

@keyframes blinkTimer {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0.5; }
}

@keyframes fadeInParagraph {
    from { opacity: 0.3; }
    to { opacity: 1; }
}

/* --- PREMIUM ANIMATIONS FROM KSN.ING --- */
@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-10px) rotate(1deg); }
    66% { transform: translateY(5px) rotate(-0.5deg); }
}

@keyframes floatReverse {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(10px) rotate(-1deg); }
    66% { transform: translateY(-5px) rotate(0.5deg); }
}

@keyframes particleFloat {
    0%, 100% { transform: translateY(0px) translateX(0px) scale(1); }
    25% { transform: translateY(-20px) translateX(10px) scale(1.1); }
    50% { transform: translateY(-10px) translateX(-15px) scale(0.9); }
    75% { transform: translateY(-30px) translateX(5px) scale(1.05); }
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 5px rgba(var(--mauve-rgb), 0.3); }
    50% { box-shadow: 0 0 20px rgba(var(--mauve-rgb), 0.6), 0 0 30px rgba(var(--mauve-rgb), 0.3); }
}

@keyframes morphAnimation {
    0% { 
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    }
    25% { 
        border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
    }
    50% { 
        border-radius: 70% 30% 60% 40% / 40% 50% 60% 30%;
    }
    75% { 
        border-radius: 40% 70% 30% 60% / 60% 40% 50% 70%;
    }
    100% { 
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    }
}

/* --- FLOATING SCROLL TO TOP BUTTON --- */
.scroll-top {
    position: fixed !important;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(var(--mauve-rgb), 0.9), rgba(var(--blue-rgb), 0.8));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(var(--surface0-rgb), 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--base);
    font-size: 1.2rem;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    z-index: 9999 !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(var(--mauve-rgb), 0.3);
    cursor: pointer;
    pointer-events: auto;
    will-change: transform;
}

.scroll-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.scroll-top:hover {
    background: linear-gradient(135deg, rgba(var(--mauve-rgb), 1), rgba(var(--blue-rgb), 0.9));
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2), 0 6px 15px rgba(var(--mauve-rgb), 0.4);
}

.scroll-top:active {
    transform: translateY(-1px) scale(0.98);
}


/* --- RESPONSIVE ADJUSTMENTS --- */
@media (max-width: 900px) {
    .settings-content-area {
        flex-direction: column;
        min-height: 0;
    }
    .settings-controls {
        border-right: none;
        border-bottom: 1px solid var(--surface0);
        max-height: 50vh;
        flex-shrink: 0;
        max-width: none;
    }
    .settings-preview-area {
        flex-grow: 1;
    }
}

@media (max-width: 768px) {
    /* Reduce complex 3D effects on mobile for performance while maintaining premium feel */
    .book-card:hover {
        transform: translateY(-8px) scale(1.02);
        box-shadow: 
            0 12px 25px rgba(0, 0, 0, 0.15),
            0 4px 10px rgba(0, 0, 0, 0.1);
    }
    
    .typing-container .shape {
        animation-duration: 15s; /* Slower animations on mobile */
    }
    
    /* Maintain glassmorphism but reduce blur for performance */
    header {
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        padding: 0.75rem 1rem;
    }
    
    .typing-container {
        backdrop-filter: blur(15px);
        padding: 1.5rem;
    }
    
    .book-card {
        backdrop-filter: blur(15px);
    }
    
    .logo-link { font-size: 1.3rem; }
    main { padding: 1rem; }
    .book-library-header h2 { font-size: 1.5rem; }
    .add-book-btn { padding: 0.5rem 1rem; font-size: 0.85rem; }
    .books-container { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
    .book-cover { height: 200px; }
    .book-title { font-size: 0.9rem; }
    .reader-header { top: 53px; }
    .reader-header-top { flex-direction: column; gap: 0.5rem; padding: 0 0.5rem; }
    .stat-value { font-size: 1rem; }
    .book-title-reader { font-size: 1.3rem; }
    .chapter-title-reader { font-size: 1rem; }
    .settings-header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .settings-header h2 {
        font-size: 1.2rem;
        order: 0;
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }
    .settings-header .back-button {
        order: 1;
        margin-right: auto;
    }
    .settings-header .settings-header-actions {
        order: 2;
        width: 100%;
        justify-content: center;
        margin-top: 0.25rem;
    }
     .settings-header .settings-header-actions .action-btn {
        flex-grow: 1;
        max-width: calc(50% - 0.375rem);
    }
    .settings-controls, .preview-wrapper { padding: 1rem; }
    .static-page-header {
        padding: 0.75rem 1rem;
    }
    .static-page-header h2 {
        font-size: 1.2rem;
    }
    .static-page-content-area {
        padding: 1rem 1.5rem;
    }
    .about-section h3 {
        font-size: 1.15rem;
    }
    .about-section p {
        font-size: 0.9rem;
    }
    
    .donate-card {
        padding: 1.5rem;
        margin: 0 1rem;
    }
    
    .donate-card h3 {
        font-size: 1.2rem;
    }
    
    .donate-btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
    .details-content { flex-direction: column; align-items: center; text-align: center; margin-top: 1rem; gap: 1.5rem;}
    .details-back-button { position: static; margin-bottom: 1rem; width: auto; }
    .details-cover-container { width: 180px; margin-bottom: 0.5rem; }
    .details-book-title-heading { font-size: 1.6rem; }
    .details-book-author { font-size: 1rem; }
    .details-stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
    .details-actions { flex-direction: column; width: 100%; }
    .details-actions .action-btn { width: 100%; }
    .unified-modal-content { max-width: 95%; max-height: 90vh; }
    .unified-modal-header { padding: 0.75rem 1rem; }
    .unified-modal-title-heading { font-size: 1.1rem; }
    .unified-modal-body { padding: 1rem; }
    .unified-modal-actions { padding: 0.75rem 1rem; flex-direction: column-reverse; gap: 0.5rem;}
    .modal-action-btn { width: 100%; }
    
    /* Scroll to top button adjustments for mobile */
    .scroll-top {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .scroll-top:hover {
        transform: translateY(-2px) scale(1.02);
    }
    .unified-modal-body .chapter-selection-main {
        flex-direction: column;
    }
     .unified-modal-body .chapters-list-container {
        flex: 1 1 40%;
        min-height: 150px;
        max-height: 40vh;
    }
    .unified-modal-body .chapter-preview {
        flex: 1 1 50%;
        min-height: 150px;
        max-height: 40vh;
    }
    .completion-content { padding: 2rem 1.5rem; }
    .completion-content h2 { font-size: 1.8rem; }
    .completion-content p { font-size: 1rem; }
    .completion-stats { flex-direction: column; gap: 1rem; }
    .completion-stat .value { font-size: 1.8rem; }
}
@media (max-width: 480px) {
    .books-container { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .book-cover { height: 170px; }
    .book-title { font-size: 0.85rem; }
    .reading-stats { display: grid; grid-template-columns: 1fr 1fr; width: 100%; justify-items: center; gap: 0.5rem; } /* Reduced gap */
    .stat { min-width: auto; }
    .reader-header-top .back-button { align-self: flex-start; margin-bottom: 0.5rem;}
    /* .typing-text { font-size: 1rem; } */ /* This is :root controlled, reader specific font-size */
}
