:root {
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --accent-blue: #3b82f6;
    --bg-white: #ffffff;
    --bg-light: #f8f9fa;
    --border-light: #e5e7eb;
    --highlight-bg: #fef3c7;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

/* Dark mode variables */
[data-theme="dark"] {
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent-blue: #60a5fa;
    --bg-white: #0f172a;
    --bg-light: #1e293b;
    --border-light: #334155;
    --highlight-bg: #E84A2F;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

/* Auto dark mode based on system preference (when no manual choice made) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --accent-blue: #60a5fa;
        --bg-white: #0f172a;
        --bg-light: #1e293b;
        --border-light: #334155;
        --highlight-bg: #E84A2F;
        --shadow-color: rgba(0, 0, 0, 0.4);
    }
}

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

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background-color: var(--bg-white);
    color: var(--text-primary);
    line-height: 1.8;
    font-size: 18px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 60px 24px;
}

@media (max-width: 600px) {
    .container {
        padding: 40px 20px;
    }
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 48px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--text-primary);
}

.chapter-label {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

h1 {
    font-size: 2.5rem;
    font-weight: 400;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.meta {
    font-size: 14px;
    color: var(--text-primary);
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

/* Heading Styles */
h2 {
    font-size: 1.75rem;
    font-weight: 400;
    margin-top: 56px;
    margin-bottom: 24px;
    color: var(--text-primary);
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 40px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Text Styles */
p {
    margin-bottom: 20px;
}

blockquote {
    background-color: var(--bg-light);
    border-left: 4px solid var(--accent-blue);
    padding: 20px 24px;
    margin: 32px 0;
    font-style: italic;
    text-align: center;
}

blockquote strong {
    font-style: normal;
    color: var(--accent-blue);
}

/* Image Styles */
.image {
    margin: 40px 0;
    text-align: center;
}

.image img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    border: 1px solid transparent;
    transition: border-color 0.3s ease;
}

/* Subtle border for SVGs in dark mode */
[data-theme="dark"] .image img {
    border-color: rgba(255, 255, 255, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .image img {
        border-color: rgba(255, 255, 255, 0.15);
    }
}

.image-caption {
    font-size: 14px;
    color: var(--text-primary);
    margin-top: 12px;
    font-style: italic;
}

/* Math Block Styles */
.math-block {
    margin: 32px 0;
    text-align: center;
    overflow-x: auto;
}

/* Responsive math scaling */
@media (max-width: 600px) {
    .math-block {
        font-size: 0.85em;
    }
}

@media (max-width: 400px) {
    .math-block {
        font-size: 0.7em;
    }
}

/* List Styles */
ul, ol {
    margin: 20px 0;
    padding-left: 28px;
}

li {
    margin-bottom: 12px;
}

/* Utility Styles */
.highlight {
    background-color: var(--highlight-bg);
    padding: 2px 6px;
    border-radius: 4px;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border: 1px solid var(--border-light);
    border-radius: 50%;
    background-color: var(--bg-light);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
    z-index: 1000;
}

/* Stronger contrast for moon icon in light mode */
.theme-toggle .moon-icon {
    color: #1a1a2e;
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
}

.theme-toggle:hover svg {
    transform: rotate(15deg);
}

/* Hide the inactive icon */
.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }

[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
[data-theme="dark"] .theme-toggle .moon-icon { display: none; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .sun-icon { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .moon-icon { display: none; }
}

/* Footer Styles */
footer {
    margin-top: 80px;
    padding-top: 32px;
    border-top: 1px solid var(--border-light);
    text-align: center;
    font-size: 14px;
    color: var(--text-primary);
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

footer a:not(.nav-link):not(.home-button) {
    color: var(--accent-blue);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

footer a:not(.nav-link):not(.home-button):hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Home Button */
.home-button {
    display: inline-block;
    flex-shrink: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 8px;
}

.home-button:hover {
    transform: scale(1.08);
    opacity: 1;
    text-decoration: none;
}

.home-button img {
    width: 120px;
    height: auto;
    border-radius: 8px;
    display: block;
    box-shadow: none;
    border: 1px solid transparent;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

[data-theme="dark"] .home-button img {
    box-shadow: 0 2px 8px var(--shadow-color);
    border-color: var(--border-light);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .home-button img {
        box-shadow: 0 2px 8px var(--shadow-color);
        border-color: var(--border-light);
    }
}

.home-button:hover img {
    box-shadow: 0 4px 12px var(--shadow-color);
}

/* Footer Navigation */
.footer-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.footer-nav .nav-side {
    flex: 1;
    display: flex;
}

.footer-nav .nav-side.left {
    justify-content: flex-end;
    padding-right: 24px;
}

.footer-nav .nav-side.right {
    justify-content: flex-start;
    padding-left: 24px;
}

.nav-link {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    color: var(--text-primary);
    text-decoration: none;
    padding: 4px 0.6em;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.nav-link:hover {
    background-color: var(--highlight-bg);
    text-decoration: none;
}

/* Responsive layout for mobile */
@media (max-width: 600px) {
    .footer-nav {
        flex-direction: column;
        gap: 16px;
    }

    .footer-nav .nav-side.left,
    .footer-nav .nav-side.right {
        justify-content: center;
        padding: 0;
    }
    
    .nav-link {
        font-size: 15px;
    }
}
