/* Base styles and CSS reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Updated color palette with purple and ensuring WCAG 2.1 compliance */
    --primary-color: #2D1B69;    /* Deep purple - meets contrast requirements */
    --secondary-color: #6B4EFF;  /* Bright purple - meets contrast requirements */
    --accent-color: #9B7DFF;     /* Light purple - for subtle accents */
    --text-color: #1A1A1A;       /* Near black - for maximum readability */
    --background-color: #FFFFFF; /* Pure white - for maximum contrast */
    --link-color: #4A3B8B;       /* Dark purple - for links */
    --link-hover-color: #6B4EFF; /* Bright purple - for hover states */
    --max-width: 800px;          /* Optimized for reading (60-75 characters per line) */
    --line-height: 1.7;          /* Better line height for reading */
    --reading-font-size: 1.1rem; /* Slightly larger base font for better readability */
    --border-radius: 8px;
    --shadow-light: 0 2px 8px rgba(45, 27, 105, 0.08);
    --shadow-medium: 0 4px 16px rgba(45, 27, 105, 0.12);
}

body {
    font-family: Georgia, 'Times New Roman', Times, serif; /* Serif font for better reading */
    line-height: var(--line-height);
    color: var(--text-color);
    background-color: var(--background-color);
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    font-size: var(--reading-font-size);
}

/* Reading Progress Indicator */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background: linear-gradient(90deg, var(--secondary-color), var(--accent-color));
    z-index: 1000;
    transition: width 0.2s ease-out;
}

/* Typography optimized for reading */
h1, h2, h3, h4 {
    color: var(--primary-color);
    margin: 2rem 0 1.5rem;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 600;
    line-height: 1.3;
}

h1 {
    font-size: 2.75rem;
    line-height: 1.2;
    margin-bottom: 0.5rem;
    text-align: center;
}

h2 {
    font-size: 2.25rem;
    margin-top: 3rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--accent-color);
}

h3 {
    font-size: 1.75rem;
    margin-top: 2.5rem;
}

h4 {
    font-size: 1.4rem;
    margin-top: 2rem;
    color: var(--secondary-color);
}

p {
    margin-bottom: 1.5rem;
    text-align: justify;
    hyphens: auto;
}

/* Improve paragraph spacing after headings */
h1 + p, h2 + p, h3 + p, h4 + p {
    margin-top: 0.5rem;
}

/* Better list styling for readability */
ul, ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

li {
    margin: 0.75rem 0;
    line-height: 1.6;
}

/* Navigation */
nav {
    background: rgba(45, 27, 105, 0.02);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    border: 1px solid rgba(45, 27, 105, 0.1);
}

nav ul {
    list-style: none;
    padding: 0;
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

nav a {
    color: var(--link-color);
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
    font-weight: 500;
}

nav a:hover,
nav a:focus {
    color: var(--link-hover-color);
    background: rgba(107, 78, 255, 0.1);
    text-decoration: none;
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-link {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 0.75rem 1.25rem;
    background: var(--primary-color);
    color: var(--background-color);
    text-decoration: none;
    border-radius: 0 0 var(--border-radius) 0;
    font-weight: 600;
}

.skip-link:focus {
    position: absolute;
    left: 0;
    top: 0;
    text-decoration: underline;
}

/* Main content */
main {
    margin: 2rem 0;
}

/* Enhanced article layout */
article {
    background: var(--background-color);
    padding: 1rem 0;
}

/* Section spacing for better reading flow */
section {
    margin: 3rem 0;
    padding: 2rem 0;
}

section:first-child {
    margin-top: 0;
    padding-top: 0;
}

.subtitle {
    font-size: 1.4rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
    text-align: center;
    font-weight: 400;
    font-style: italic;
}

.authors {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 3rem;
    font-style: italic;
    text-align: center;
    font-weight: 500;
}

/* Download options */
.download-options {
    list-style: none;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 2rem 0;
    justify-content: center;
}

.download-options a {
    display: inline-block;
    padding: 1rem 2rem;
    background-color: var(--secondary-color);
    color: var(--background-color);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: var(--shadow-light);
}

.download-options a:hover,
.download-options a:focus {
    background-color: var(--link-hover-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Enhanced Table of Contents */
#table-of-contents {
    background: rgba(45, 27, 105, 0.02);
    padding: 2rem;
    border-radius: var(--border-radius);
    border: 1px solid rgba(45, 27, 105, 0.1);
    margin: 3rem 0;
}

#table-of-contents h2 {
    margin-top: 0;
    text-align: center;
    border-bottom: none;
    margin-bottom: 1.5rem;
}

#table-of-contents ul {
    list-style: none;
    padding-left: 0;
    max-width: none;
}

#table-of-contents li {
    margin: 1rem 0;
    padding-left: 1.5rem;
    position: relative;
}

#table-of-contents li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent-color);
    font-weight: bold;
}

#table-of-contents a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem;
    border-radius: 4px;
    display: block;
    transition: all 0.2s ease;
}

#table-of-contents a:hover,
#table-of-contents a:focus {
    color: var(--link-hover-color);
    background: rgba(107, 78, 255, 0.08);
    text-decoration: none;
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Chapter content with better spacing */
.chapter-content,
.preface-content {
    margin: 2rem 0;
    line-height: var(--line-height);
}

/* Enhanced blockquote styling */
blockquote {
    background: rgba(107, 78, 255, 0.05);
    border-left: 4px solid var(--secondary-color);
    margin: 2rem 0;
    padding: 1.5rem 2rem;
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
    font-style: italic;
    position: relative;
}

blockquote p {
    margin-bottom: 0;
    font-size: 1.1rem;
}

/* Links with better styling */
a {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-color: var(--accent-color);
    text-underline-offset: 3px;
    transition: all 0.2s ease;
}

a:hover,
a:focus {
    color: var(--link-hover-color);
    text-decoration-color: var(--link-hover-color);
    text-decoration-thickness: 2px;
}

/* Footer */
footer {
    margin-top: 4rem;
    padding: 2rem 0 1rem;
    border-top: 2px solid var(--accent-color);
    text-align: center;
    color: var(--primary-color);
    background: rgba(45, 27, 105, 0.02);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

/* Book cover with better presentation */
.book-cover {
    margin: 3rem auto;
    text-align: center;
    max-width: 544px; /* Restore to original image dimensions */
}

.book-cover img {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    transition: transform 0.3s ease;
}

.book-cover img:hover {
    transform: scale(1.02);
}

/* Preface section with enhanced styling */
.preface-content h3 {
    color: var(--secondary-color);
    border-bottom: 1px solid var(--accent-color);
    padding-bottom: 0.5rem;
    margin-top: 2.5rem;
}

.preface-content h4 {
    color: var(--primary-color);
    margin-top: 2rem;
}

.preface-content p {
    text-align: justify;
}

.preface-content h3:first-child {
    margin-top: 0;
}

/* Enhanced mobile responsiveness */
@media (max-width: 768px) {
    body {
        padding: 1rem;
        font-size: 1rem;
    }

    h1 {
        font-size: 2.25rem;
    }

    h2 {
        font-size: 1.875rem;
    }

    h3 {
        font-size: 1.5rem;
    }

    nav ul {
        flex-direction: column;
        gap: 0.5rem;
    }

    nav a {
        text-align: center;
        padding: 1rem;
        font-size: 1.1rem; /* Larger text for better touch targets */
    }

    .book-cover {
        max-width: 400px; /* Slightly larger on tablets */
        margin: 2rem auto;
    }

    section {
        padding: 1rem 0;
        margin: 2rem 0;
    }

    blockquote {
        padding: 1rem 1.5rem;
        margin: 1.5rem 0;
    }

    #table-of-contents {
        padding: 1.5rem;
    }

    /* Larger dark mode toggle for mobile */
    .reading-mode-toggle {
        padding: 1rem 1.25rem;
        font-size: 1rem;
        top: 15px;
        right: 15px;
    }
}

@media (max-width: 480px) {
    .book-cover {
        max-width: 300px; /* Reasonable size on phones */
    }

    h1 {
        font-size: 2rem;
    }

    body {
        padding: 0.75rem;
    }

    /* Even larger navigation for small phones */
    nav a {
        font-size: 1.2rem; /* Even larger for small screens */
        padding: 1.25rem;
    }

    /* Larger dark mode toggle for small phones */
    .reading-mode-toggle {
        padding: 1.25rem 1.5rem;
        font-size: 1.1rem;
        top: 10px;
        right: 10px;
    }
}

/* Accessibility and motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (forced-colors: active) {
    a {
        color: LinkText;
        text-decoration-color: LinkText;
    }
}

/* Focus styles for better keyboard navigation */
:focus {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Print styles for better reading when printed */
@media print {
    body {
        max-width: none;
        font-size: 12pt;
        line-height: 1.5;
        padding: 0;
    }

    nav, .download-options {
        display: none;
    }

    .reading-progress {
        display: none;
    }

    h2 {
        page-break-before: always;
    }

    blockquote {
        border: 1px solid #ccc;
        background: #f9f9f9;
    }
}

/* Reading mode toggle styles */
.reading-mode-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--primary-color);
    color: var(--background-color);
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    z-index: 999;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-light);
}

.reading-mode-toggle:hover,
.reading-mode-toggle:focus {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

/* Dark reading mode */
body.dark-mode {
    --text-color: #E8E8E8;
    --background-color: #1A1A1A;
    --primary-color: #9B7DFF;
    --secondary-color: #B8A3FF;
    --accent-color: #6B4EFF;
    --link-color: #B8A3FF;
    --link-hover-color: #D4C7FF;
}

body.dark-mode .reading-progress {
    background: linear-gradient(90deg, var(--secondary-color), var(--accent-color));
}

body.dark-mode nav,
body.dark-mode #table-of-contents,
body.dark-mode footer {
    background: rgba(155, 125, 255, 0.05);
    border-color: rgba(155, 125, 255, 0.2);
}

body.dark-mode blockquote {
    background: rgba(155, 125, 255, 0.08);
    border-left-color: var(--secondary-color);
}

/* Bookmark functionality */
.bookmark-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--primary-color);
    color: var(--background-color);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 400px;
    animation: slideIn 0.3s ease-out;
}

.bookmark-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.bookmark-resume,
.bookmark-dismiss {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.bookmark-resume {
    background-color: var(--secondary-color);
    color: var(--background-color);
}

.bookmark-dismiss {
    background-color: transparent;
    color: var(--background-color);
    border: 1px solid var(--background-color);
}

.bookmark-resume:hover,
.bookmark-resume:focus,
.bookmark-dismiss:hover,
.bookmark-dismiss:focus {
    opacity: 0.8;
}

.bookmark-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--primary-color);
    color: var(--background-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1000;
}

.bookmark-indicator.active {
    opacity: 1;
    transform: translateY(0);
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.bookmark-resume:focus,
.bookmark-dismiss:focus {
    outline: 2px solid var(--background-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (forced-colors: active) {
    .bookmark-notification {
        border: 2px solid CanvasText;
    }
    
    .bookmark-resume,
    .bookmark-dismiss {
        border: 2px solid CanvasText;
    }
} 