/* CSS Custom Properties for Theming */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #2c3e50;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-inverse: #ffffff;
    --border-color: #eeeeee;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
    --accent-primary: #2c3e50;
    --accent-hover: #f5f5f5;
    --success-bg: #d4edda;
    --success-text: #155724;
    --success-border: #c3e6cb;
    --error-bg: #f8d7da;
    --error-text: #721c24;
    --error-border: #f5c6cb;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2c2c2c;
    --bg-tertiary: #f5f5f5;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-inverse: #333333;
    --border-color: #444444;
    --shadow-light: rgba(0, 0, 0, 0.3);
    --shadow-medium: rgba(0, 0, 0, 0.4);
    --accent-primary: #4aa3df;
    --accent-hover: #3498db;
    --success-bg: #1e4d2b;
    --success-text: #a3d9a5;
    --success-border: #2d5a31;
    --error-bg: #4d1e1e;
    --error-text: #f5a3a3;
    --error-border: #5a2d2d;
}

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

/* Improve mobile performance */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling for better UX */
html {
    scroll-behavior: smooth;
}

/* Prevent horizontal scrolling on mobile */
body {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.reader-container-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Fixed Theme Toggle - Top Right */
.theme-toggle-fixed {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0.5rem;
    box-shadow: 0 2px 8px var(--shadow-medium);
    transition: background-color 0.3s ease;
}

/* Hamburger Menu Button - Bottom Right */
.hamburger-menu {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.hamburger-menu:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hamburger-icon span {
    width: 20px;
    height: 2px;
    background: var(--text-inverse);
    border-radius: 1px;
    transition: all 0.3s ease;
}


.hamburger-menu:hover .hamburger-icon span {
    background: var(--text-primary);
}

.hamburger-menu.active .hamburger-icon span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-menu.active .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.hamburger-menu.active .hamburger-icon span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Navigation Overlay */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
}

.nav-overlay.active {
    opacity: 1;
    visibility: visible;
}

.nav-menu {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    max-width: 80vw;
    background: var(--bg-secondary);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.nav-overlay.active .nav-menu {
    transform: translateX(0);
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-header h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    margin: 0;
}

.nav-close {
    background: none;
    font-size: 1.5rem;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.nav-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.nav-content {
    flex: 1;
    padding: 1rem 0;
}

.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links li {
    margin: 0;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.nav-links a:hover {
    background: var(--border-color);
    border-left-color: var(--accent-primary);
}

.nav-links a.active {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-left-color: var(--accent-hover);
}

.nav-links a.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.nav-icon {
    font-size: 2rem;
    /* width: 24px;
    height: 24px; */
}

/* Theme Toggle in Navigation */
.nav-theme-toggle {
    border-top: 1px solid var(--border-color);
    padding: 1rem 0;
    margin-top: auto; /* Push to bottom of nav */
}

.theme-toggle-link {
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

/* .theme-toggle-link:hover {
    background: var(--border-color);
    border-left-color: var(--accent-primary);
} */

/* Animated Theme Toggle */
.theme-toggle-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.toggle-checkbox {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.toggle-slot {
    position: relative;
    min-height: 2.7em;
    width: 5em;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 2.5em;
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
    transition: background-color 250ms, border-color 250ms;
}

.toggle-checkbox:checked~.toggle-slot {
    background-color: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.toggle-button {
    transform: translate(0.4em, 0.4em);
    position: absolute;
    height: 1.7em;
    width: 1.7em;
    border-radius: 50%;
    background-color: #ffeccf;
    box-shadow: inset 0px 0px 0px 0.2em #ffbb52;
    transition: background-color 250ms, border-color 250ms, transform 500ms cubic-bezier(.26, 2, .46, .71);
}

.toggle-checkbox:checked~.toggle-slot .toggle-button {
    background-color: #485367;
    box-shadow: inset 0px 0px 0px 0.2em white;
    transform: translate(2.9em, 0.4em);
}

.sun-icon {
    position: absolute;
    height: 1.5em;
    width: 1.5em;
    color: #ffbb52;
}

.sun-icon-wrapper {
    position: absolute;
    height: 1.5em;
    width: 1.5em;
    opacity: 1;
    transform: translate(2.8em, 0.5em) rotate(-25deg);
    transform-origin: 50% 50%;
    /* transition: opacity 150ms, transform 500ms cubic-bezier(.26,2,.46,.71); */
}

.toggle-checkbox:checked~.toggle-slot .sun-icon-wrapper {
    opacity: 0;
    transform: translate(2.8em, 0.5em);
}

.moon-icon {
    position: absolute;
    height: 1.5em;
    width: 1.5em;
    color: white;
}

.moon-icon-wrapper {
    position: absolute;
    height: 1.5em;
    width: 1.5em;
    opacity: 0;
    transform: translate(0.5em, 0.5em) rotate(15deg);
    transform-origin: 50% 50%;
    /* transition: opacity 150ms, transform 500ms cubic-bezier(.26,2.5,.46,.71); */
}

.toggle-checkbox:checked~.toggle-slot .moon-icon-wrapper {
    opacity: 1;
    transform: translate(0.4em, 0.5em) rotate(0deg);
}

/* Hover effects for the toggle */
.theme-toggle-wrapper:hover .toggle-slot {
    border-color: var(--accent-primary);
    box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
}

.theme-toggle-wrapper:hover .toggle-button {
    transform: translate(0.4em, 0.4em) scale(1.05);
}

.toggle-checkbox:checked~.toggle-slot:hover .toggle-button {
    transform: translate(2.9em, 0.4em) scale(1.05);
}

/* Focus styles for accessibility */
.toggle-checkbox:focus~.toggle-slot {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Ensure toggle is properly aligned in navigation */
.nav-links .theme-toggle-wrapper {
    margin: 0;
    padding: 0.25rem;
}

/* Main Content */
.main-content {
    min-height: 98vh;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    padding: 2rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border: 1px solid var(--error-border);
}

.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    padding: 1rem;
    border-radius: 4px;
    margin: 1rem 0;
    border: 1px solid var(--success-border);
}

/* Responsive Design */
/* @media (max-width: 1200px) {
    .container {
        padding: 0 20px;
    }
} */

@media (max-width: 1024px) {
    /* .container {
        padding: 0 16px;
    } */

    /* Tablet-specific optimizations */
    .nav-links {
        gap: 1.5rem;
    }

    .nav-links a {
        padding: 0.6rem 1.2rem;
        font-size: 0.95rem;
    }
}

@media (max-width: 768px) {
    .theme-toggle-fixed {
        top: 0.75rem;
        right: 0.75rem;
        padding: 0.4rem;
    }

    .toggle-slot {
        height: 2.2em;
        width: 4.4em;
    }

    .toggle-button {
        height: 1.5em;
        width: 1.5em;
        transform: translate(0.35em, 0.35em);
    }

    .toggle-checkbox:checked~.toggle-slot .toggle-button {
        transform: translate(2.55em, 0.35em);
    }

    .sun-icon-wrapper {
        height: 1.3em;
        width: 1.3em;
        transform: translate(0.45em, 0.45em) rotate(15deg);
    }

    .moon-icon-wrapper {
        height: 1.3em;
        width: 1.3em;
        transform: translate(2.4em, 0.45em) rotate(0deg);
    }

    .toggle-checkbox:checked~.toggle-slot .moon-icon-wrapper {
        transform: translate(2.65em, 0.45em) rotate(-15deg);
    }

    .theme-toggle-wrapper:hover .toggle-button {
        transform: translate(0.35em, 0.35em) scale(1.05);
    }

    .toggle-checkbox:checked~.toggle-slot:hover .toggle-button {
        transform: translate(2.55em, 0.35em) scale(1.05);
    }

    .hamburger-menu {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 56px;
        height: 56px;
    }

    .nav-menu {
        width: 280px;
        max-width: 85vw;
    }

    .nav-header {
        padding: 1.5rem;
    }

    .nav-header h2 {
        font-size: 1.3rem;
    }

    .nav-links a {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    /* .container {
        padding: 0 15px;
    } */

    .main-content {
        padding: 1rem 0;
    }
}

@media (max-width: 480px) {
    .theme-toggle-fixed {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.3rem;
    }

    .toggle-slot {
        height: 2em;
        width: 4em;
    }

    .toggle-button {
        height: 1.3em;
        width: 1.3em;
        transform: translate(0.35em, 0.35em);
    }

    .toggle-checkbox:checked~.toggle-slot .toggle-button {
        transform: translate(2.35em, 0.35em);
    }

    .sun-icon,
    .moon-icon {
        height: 1.1em;
        width: 1.1em;
    }

    .sun-icon-wrapper {
        height: 1.1em;
        width: 1.1em;
        transform: translate(0.45em, 0.45em) rotate(15deg);
    }

    .moon-icon-wrapper {
        height: 1.1em;
        width: 1.1em;
        transform: translate(2.2em, 0.45em) rotate(0deg);
    }

    .toggle-checkbox:checked~.toggle-slot .moon-icon-wrapper {
        transform: translate(2.45em, 0.45em) rotate(-15deg);
    }

    .theme-toggle-wrapper:hover .toggle-button {
        transform: translate(0.35em, 0.35em) scale(1.05);
    }

    .toggle-checkbox:checked~.toggle-slot:hover .toggle-button {
        transform: translate(2.35em, 0.35em) scale(1.05);
    }

    .hamburger-menu {
        bottom: 1rem;
        right: 1rem;
        width: 52px;
        height: 52px;
    }

    .hamburger-icon span {
        width: 18px;
    }

    .nav-menu {
        width: 260px;
        max-width: 90vw;
    }

    .nav-header {
        padding: 1rem;
    }

    .nav-header h2 {
        font-size: 1.2rem;
    }

    .nav-links a {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .nav-icon {
        font-size: 1.1rem;
        width: 20px;
        height: 20px;
    }

    /* .container {
        padding: 0 12px;
    } */

    .main-content {
        padding: 0.75rem 0;
    }
}

/* Mobile-first responsive utilities */
@media (max-width: 320px) {
    /* .container {
        padding: 0 8px;
    } */

    .nav-brand {
        font-size: 1.2rem;
    }

    .nav-links a {
        padding: 0.5rem 0.7rem;
        font-size: 0.8rem;
    }
}