/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Improved accessibility: Ensure focus is visible */
:focus {
    outline: 3px solid #4d90fe;
    outline-offset: 2px;
}

:root {
    /* Light theme variables with improved contrast ratios for WCAG 2.2 AA */
    --bg-gradient: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    --text-color: #222222; /* Darker for better contrast */
    --text-light: #ffffff; /* Full white for better contrast */
    --card-bg: #ffffff; /* Full white for better contrast */
    --input-bg: #ffffff;
    --input-border: #767676; /* Darker for better contrast */
    --input-focus: #4d90fe; /* Focus color that meets contrast requirements */
    --button-primary: #4361ee; /* Adjusted for better contrast */
    --button-hover: #3a56d4; /* Darker for hover state */
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
    --error-color: #d32f2f; /* Adjusted for better contrast */
    --success-color: #2e7d32; /* Adjusted for better contrast */
    --border-color: #767676; /* Darker for better contrast */
    --overlay-bg: rgba(0, 0, 0, 0.7); /* Darker for better contrast */
    --reading-time-bg: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    --reading-time-text: #0d47a1;
    --reading-time-accent: #1976d2;
    --focus-outline: #4d90fe; /* Consistent focus outline color */
    --link-color: #0056b3; /* Accessible link color */
    --link-hover: #003d82; /* Darker for hover state */
    
    /* Font sizes with rem units for better scaling */
    --font-size-base: 1rem;
    --font-size-sm: 0.875rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;
    
    /* Spacing variables for consistency */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border radius */
    --border-radius-sm: 0.25rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 0.75rem;
    --border-radius-xl: 1rem;
}

[data-theme="dark"] {
    /* Dark theme variables with improved contrast ratios for WCAG 2.2 AA */
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --text-color: #f0f0f0; /* Lighter for better contrast */
    --text-light: #ffffff; /* Full white for better contrast */
    --card-bg: #1e293b; /* Adjusted for better contrast */
    --input-bg: #2d3748;
    --input-border: #a0aec0; /* Lighter for better contrast */
    --input-focus: #4d90fe; /* Focus color that meets contrast requirements */
    --button-primary: #4361ee; /* Adjusted for better contrast */
    --button-hover: #3a56d4; /* Darker for hover state */
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.4);
    --error-color: #ef5350; /* Brighter for better contrast */
    --success-color: #4caf50; /* Brighter for better contrast */
    --border-color: #a0aec0; /* Lighter for better contrast */
    --overlay-bg: rgba(0, 0, 0, 0.8); /* Darker for better contrast */
    --reading-time-bg: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    --reading-time-text: #c5cae9; /* Lighter for better contrast */
    --reading-time-accent: #90caf9; /* Lighter for better contrast */
    --focus-outline: #4d90fe; /* Consistent focus outline color */
    --link-color: #63b3ed; /* Accessible link color for dark mode */
    --link-hover: #90caf9; /* Lighter for hover state */
}

/* Base HTML elements with improved accessibility */
html {
    font-size: 100%; /* Ensures text resizes properly */
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-gradient);
    min-height: 100vh;
    transition: all 0.3s ease;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: var(--font-size-base);
}

/* Container with improved responsive layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-md);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

/* Responsive container adjustments */
@media screen and (max-width: 1280px) {
    .container {
        max-width: 100%;
        padding: var(--spacing-md);
    }
}

@media screen and (max-width: 768px) {
    .container {
        padding: var(--spacing-sm);
    }
}

/* Header with improved accessibility */
.header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    padding: var(--spacing-2xl) 0 var(--spacing-xl) 0;
    position: relative;
}

.header h1 {
    font-size: var(--font-size-3xl);
    color: var(--text-light);
    margin-bottom: var(--spacing-md);
    line-height: 1.2;
}

@media screen and (max-width: 768px) {
    .header {
        padding: var(--spacing-xl) 0 var(--spacing-lg) 0;
        margin-bottom: var(--spacing-lg);
    }
    
    .header h1 {
        font-size: var(--font-size-2xl);
    }
}

@media screen and (max-width: 480px) {
    .header {
        padding: var(--spacing-lg) 0 var(--spacing-md) 0;
    }
    
    .header h1 {
        font-size: var(--font-size-xl);
    }
}

/* PWA Install Button Styles with improved accessibility */
.install-button {
    display: none;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--button-primary);
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3);
    white-space: nowrap;
    z-index: 100;
    /* Accessibility improvements */
    aria-label: "Install application";
    role: "button";
}

.install-button:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.4);
}

.install-button:focus {
    outline: 3px solid var(--focus-outline);
    outline-offset: 2px;
}

.install-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(67, 97, 238, 0.3);
}

.install-button i {
    font-size: var(--font-size-base);
}

/* PWA Install Success Message */
.install-success-message {
    position: fixed;
    top: 2rem;
    right: 2rem;
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    z-index: 10000;
    animation: slideInRight 0.3s ease-out;
}

.install-success-message i {
    font-size: 1.2rem;
}

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

/* Responsive adjustments for PWA elements */
@media (max-width: 768px) {
    .install-button {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
        position: fixed;
        bottom: 1rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1001;
    }
    
    .install-success-message {
        top: 4rem; /* Below header controls */
        right: 1rem;
        left: 1rem;
        padding: 0.8rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .install-button span {
        display: none;
    }
    
    .install-button {
        padding: 0.6rem;
        min-width: auto;
        width: 48px;
        height: 48px;
        border-radius: 50%;
    }
    
    .install-success-message {
        top: 5rem; /* Below header controls on small screens */
    }
}

/* Button Styles with improved accessibility */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--border-radius-md);
    font-weight: 600;
    font-size: var(--font-size-base);
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-align: center;
    min-height: 44px; /* Minimum touch target size */
    gap: var(--spacing-sm);
}

.btn:focus {
    outline: 3px solid var(--focus-outline);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--button-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
}

.btn-primary:hover {
    background-color: var(--button-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(67, 97, 238, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(67, 97, 238, 0.3);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

.btn-secondary:active {
    transform: translateY(0);
}

/* Responsive button adjustments */
@media screen and (max-width: 480px) {
    .btn {
        width: 100%;
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

.header-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: 1000;
}

.settings-toggle {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-color);
    font-size: 1.1rem;
}

.settings-toggle:hover {
    background: var(--button-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

/* Theme toggle within settings menu */
.settings-menu-item.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 6px;
    width: auto;
    height: auto;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    font-size: 0.9rem;
}

.settings-menu-item.theme-toggle:hover {
    background: var(--hover-bg);
    transform: none;
    box-shadow: none;
}

/* Settings Dropdown */
.settings-dropdown {
    position: relative;
}

.settings-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-color);
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1001;
}

.settings-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.settings-menu-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 0;
}

.settings-menu-item:first-child {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.settings-menu-item:last-child {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.settings-menu-item:hover,
.settings-menu-item:focus {
    background: var(--hover-bg);
    outline: none;
}

.settings-menu-item:focus {
    box-shadow: inset 0 0 0 2px var(--button-primary);
}

/* Sync Status Styles */
.sync-status-item {
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sync-online {
    color: #4CAF50;
    font-weight: 600;
}

.sync-offline {
    color: #f44336;
    font-weight: 600;
}

.sync-status-item:first-child {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.title i {
    font-size: 1.8rem;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 300;
}

/* Autocomplete Styles */
.autocomplete-container {
    position: relative;
    width: 100%;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 12px var(--shadow);
}

.autocomplete-dropdown.show {
    display: block;
}

.autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
    color: var(--text-color);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--input-focus);
    color: white;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.book-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-title {
    font-weight: 500;
    font-size: 0.95rem;
}

.book-author {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* History Panel Styles */
.history-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--card-bg);
    border-left: 1px solid var(--border-color);
    z-index: 2000;
    transition: right 0.3s ease;
    overflow-y: auto;
    box-shadow: -4px 0 20px var(--shadow);
}

.history-panel.show {
    right: 0;
}

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

.history-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-history {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.close-history:hover {
    background: rgba(255, 255, 255, 0.2);
}

.history-content {
    padding: 1rem;
}

.history-list {
    margin-bottom: 2rem;
}

.history-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.history-item:hover {
    border-color: var(--input-focus);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.history-item .history-header {
    background: none;
    padding: 0;
    border: none;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.history-item .history-header h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
}

.history-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: normal;
}

.history-author {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    font-style: italic;
}

.history-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.no-history {
    text-align: center;
    color: var(--text-color);
    opacity: 0.7;
    padding: 2rem;
    font-style: italic;
}

.history-item {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.history-item-title {
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
    font-size: 0.95rem;
}

.history-item-date {
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.7;
}

.history-item-author {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.history-item-actions {
    display: flex;
    gap: 0.5rem;
}

/* Enhanced History Action Buttons */
.history-load-btn,
.history-delete-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-load-btn {
    background: linear-gradient(135deg, var(--input-focus) 0%, #5a67d8 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(74, 144, 226, 0.3);
}

.history-load-btn:hover {
    background: linear-gradient(135deg, #5a67d8 0%, var(--input-focus) 100%);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
    transform: translateY(-1px);
}

.history-load-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(74, 144, 226, 0.3);
}

.history-delete-btn {
    background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(229, 62, 62, 0.3);
}

.history-delete-btn:hover {
    background: linear-gradient(135deg, #c53030 0%, #e53e3e 100%);
    box-shadow: 0 4px 12px rgba(229, 62, 62, 0.4);
    transform: translateY(-1px);
}

.history-delete-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(229, 62, 62, 0.3);
}

/* Add icons to buttons using pseudo-elements */
.history-load-btn::before {
    content: '📖';
    font-size: 1rem;
}

.history-delete-btn::before {
    content: '🗑️';
    font-size: 1rem;
}

/* Dark theme adjustments */
[data-theme="dark"] .history-load-btn {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    box-shadow: 0 2px 4px rgba(66, 153, 225, 0.4);
}

[data-theme="dark"] .history-load-btn:hover {
    background: linear-gradient(135deg, #3182ce 0%, #4299e1 100%);
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.5);
}

[data-theme="dark"] .history-delete-btn {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    box-shadow: 0 2px 4px rgba(245, 101, 101, 0.4);
}

[data-theme="dark"] .history-delete-btn:hover {
    background: linear-gradient(135deg, #e53e3e 0%, #f56565 100%);
    box-shadow: 0 4px 12px rgba(245, 101, 101, 0.5);
}

/* Mobile responsiveness for history buttons */
@media (max-width: 480px) {
    .history-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .history-load-btn,
    .history-delete-btn {
        flex: none;
        width: 100%;
    }
}

.history-action-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.history-action-btn:hover {
    background: var(--input-focus);
    color: white;
    border-color: var(--input-focus);
}

.history-actions {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.clear-history-btn {
    width: 100%;
    background: var(--error-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.clear-history-btn:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* API Key Management Styles */
.api-key-actions {
    margin-top: 0.5rem;
}

.checkbox-label {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.8;
    flex-direction: row !important;
    white-space: nowrap;
}

.save-checkbox {
    width: 16px !important;
    height: 16px !important;
    border: 2px solid var(--border-color);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0 !important;
    flex-shrink: 0;
    display: inline-block !important;
}

.save-checkbox:checked {
    background: #000000;
    border-color: var(--input-focus);
}

.save-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: -2px;
    left: 1px;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.checkmark {
    display: none;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Section Base Styles */
section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 10px 30px var(--shadow);
    margin-bottom: 2rem;
}

.hidden {
    display: none !important;
}
input:not([type="checkbox"]):not([type="radio"]) {
    width: 100%;
    border: 2px solid #000000 !important;
}

/* Ensure checkboxes maintain their size */
input[type="checkbox"] {
    width: auto !important;
    height: auto !important;
}
/* Input Section */
.input-section {
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.book-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-weight: 700;
    color: var(--text-color);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-label i {
    color: var(--input-focus);
    width: 16px;
}

.form-input, .form-select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: var(--input-bg);
    color: var(--text-color);
    min-height: 48px; /* Touch target requirement */
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--input-focus);
    background: var(--input-bg);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-select {
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 40px;
}

.model-info {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-color);
    opacity: 0.7;
    font-style: italic;
}

.api-key-help {
    margin-top: 6px;
}

.help-text {
    font-size: 14px;
    color: var(--text-color);
    opacity: 0.7;
    line-height: 1.4;
}

.help-text a {
    color: var(--link-color);
    text-decoration: underline;
    font-size: 14px;
}

.help-text a:hover {
    text-decoration: underline;
}

.form-input::placeholder {
    color: var(--text-light);
    opacity: 0.6;
}

.error-message {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    min-height: 1.25rem;
}

.submit-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 48px;
    margin-top: 1rem;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading Section */
.loading-section {
    text-align: center;
    max-width: 500px;
    margin: 0 auto;
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #e5e7eb;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.loading-text {
    color: var(--text-light);
    font-size: 1rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.loading-time {
    color: var(--text-light);
    font-size: 0.875rem;
}

/* Summary Section */
.summary-section {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.summary-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid #f3f4f6;
}

.summary-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.summary-author {
    font-size: 1.1rem;
    color: var(--text-light);
    font-style: italic;
    margin-bottom: 1.5rem;
}

.summary-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    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 ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
}

.download-btn {
    background: #10b981;
    color: white;
}

.download-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}

.epub-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.epub-btn:hover {
    background: linear-gradient(135deg, #e879f9 0%, #ef4444 100%);
    transform: translateY(-1px);
}

.gdocs-btn {
    background: linear-gradient(135deg, #4285f4 0%, #34a853 100%);
    color: white;
}

.gdocs-btn:hover {
    background: linear-gradient(135deg, #3367d6 0%, #2d8f47 100%);
    transform: translateY(-1px);
}

/* Context Menu Styles */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 150px;
    overflow: hidden;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    color: var(--text-color);
}

.context-menu-item:hover {
    background-color: var(--hover-bg);
}

.context-menu-item i {
    width: 16px;
    color: var(--text-light);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background-color: var(--hover-bg);
}

.modal-body {
    padding: 24px;
}

.translation-section,
.dictionary-section {
    margin-bottom: 20px;
}

.translation-section label,
.dictionary-section label {
    display: block;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    font-size: 14px;
}

.original-text,
.translated-text,
.word-text,
.definition-text {
    background: var(--input-bg);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    margin: 0;
    line-height: 1.5;
    color: var(--text-color);
}

#targetLanguage {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

/* Text Selection Highlight */
.text-selected {
    background-color: #e3f2fd !important;
    border-radius: 3px;
    padding: 2px 4px;
    margin: -2px -4px;
}

/* Mobile Responsiveness - Enhanced for professional appearance */
@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
    }
    
    .header {
        margin-bottom: 1rem;
        padding: 1rem 0;
        padding-top: 4rem; /* Add space for header controls */
    }
    
    .header-controls {
        position: fixed;
        top: 0.5rem;
        right: 0.5rem;
        background: var(--card-bg);
        border-radius: 12px;
        padding: 0.5rem;
        box-shadow: 0 4px 12px var(--shadow);
        border: 1px solid var(--border-color);
        z-index: 1000;
    }
    .settings-toggle {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
    
    .title {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .context-menu {
        min-width: 120px;
    }
    
    .context-menu-item {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    /* Ensure content doesn't overlap with fixed header controls */
    .main-content {
        margin-top: 1rem;
    }
    
    /* Form and card responsiveness */
    .form-card {
        margin: 0.5rem 0;
        padding: 1rem;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.75rem;
    }
    
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* Enhanced mobile summary display */
    .book-summary-article {
        padding: 1.5rem;
        margin: 1rem 0;
        border-radius: 12px;
    }
    
    .chapter-section {
        padding: 1.5rem;
        margin-bottom: 2rem;
        border-radius: 8px;
    }
    
    .chapter-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }
    
    .content-heading.level-1 { font-size: 1.2rem; }
    .content-heading.level-2 { font-size: 1.1rem; }
    .content-heading.level-3 { font-size: 1rem; }
    .content-heading.level-4 { font-size: 0.95rem; }
    
    .summary-paragraph {
        font-size: 1rem;
        line-height: 1.6;
        text-align: left; /* Better for mobile reading */
    }
    
    .summary-list {
        padding-left: 1.5rem;
        margin: 1rem 0;
    }
    
    .summary-quote {
        padding: 1rem 1.5rem;
        margin: 1.5rem 0;
    }
    
    .summary-quote::before {
        font-size: 2rem;
        top: 0.25rem;
        left: 0.75rem;
    }
    
    .reading-time,
    .cache-indicator {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .reading-time-icon,
    .cache-icon {
        font-size: 1rem;
    }
}

.new-summary-btn {
    background: var(--card-bg);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.new-summary-btn:hover {
    background: var(--hover-bg);
    transform: translateY(-1px);
}

/* Summary Navigation - Hidden */
.summary-navigation {
    display: none;
}

.summary-navigation h4 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 1rem;
}

.chapter-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chapter-list li {
    padding: 0.5rem 1rem;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
}

.chapter-list li:hover {
    background: #667eea;
    color: white;
    border-left-color: #4f46e5;
}

/* Summary Content - Professional and Accessible Styling */
.summary-content {
    line-height: 1.8;
}

#summaryContent {
    /* Ensure readable line-length and stronger base contrast */
    max-width: 900px;
    margin: 0 auto;
    font-size: 18px;
    line-height: 1.8;
    color: var(--text-color);
}

/* Book Summary Article - Main container */
.book-summary-article {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    margin: 1.5rem 0;
    box-shadow: 0 8px 32px var(--shadow);
    border: 1px solid var(--border-color);
}

/* Chapter Sections - Professional layout */
.chapter-section {
    margin-bottom: 3rem;
    padding: 2rem;
    background: linear-gradient(135deg, rgba(255,255,255,0.98) 0%, rgba(248,250,252,0.95) 100%);
    border-radius: 12px;
    border-left: 4px solid var(--input-focus);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    transition: all 0.3s ease;
}

[data-theme="dark"] .chapter-section {
    background: linear-gradient(135deg, rgba(52,73,94,0.98) 0%, rgba(44,62,80,0.95) 100%);
    border-left-color: var(--button-primary);
}

.chapter-section:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

/* Chapter Titles - Clear hierarchy */
.chapter-title {
    color: var(--text-color);
    margin: 0 0 1.5rem 0;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
    position: relative;
}

.chapter-title::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--input-focus);
    border-radius: 1px;
}

/* Content Headings within chapters */
.content-heading {
    color: var(--text-color);
    margin: 2rem 0 1rem 0;
    font-weight: 600;
    line-height: 1.4;
}

.content-heading.level-1 { 
    font-size: 1.4rem; 
    color: var(--input-focus);
}
.content-heading.level-2 { 
    font-size: 1.25rem; 
}
.content-heading.level-3 { 
    font-size: 1.1rem; 
}
.content-heading.level-4 { 
    font-size: 1rem; 
    font-weight: 500;
}

/* Paragraphs - Professional spacing and typography */
.summary-paragraph {
    margin: 1.25rem 0;
    line-height: 1.7;
    color: var(--text-color);
    text-align: justify;
    hyphens: auto;
}

.summary-paragraph:first-of-type {
    margin-top: 0;
}

.summary-paragraph:last-of-type {
    margin-bottom: 0;
}

/* Lists - Clear structure and spacing */
.summary-list {
    margin: 1.5rem 0;
    padding-left: 2rem;
    color: var(--text-color);
}

.summary-list.ordered {
    list-style-type: decimal;
}

.summary-list:not(.ordered) {
    list-style-type: disc;
}

.summary-list-item {
    margin-bottom: 0.75rem;
    line-height: 1.6;
    padding-left: 0.5rem;
}

.summary-list-item:last-child {
    margin-bottom: 0;
}

/* Nested lists */
.summary-list .summary-list {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.summary-list .summary-list:not(.ordered) {
    list-style-type: circle;
}

/* Emphasis elements */
.summary-emphasis {
    font-weight: 700;
    color: var(--input-focus);
}

.summary-emphasis-italic {
    font-style: italic;
    color: var(--text-color);
    font-weight: 500;
}

/* Checkmark items styling */
.checkmark-item {
    display: flex;
    align-items: flex-start;
    margin: 0.5rem 0;
    padding: 0.5rem 0;
    border-left: 3px solid var(--input-focus);
    padding-left: 1rem;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.05) 0%, transparent 100%);
    border-radius: 0 4px 4px 0;
    transition: all 0.2s ease;
}

.checkmark-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, transparent 100%);
    transform: translateX(2px);
}

.checkmark {
    color: var(--success-color);
    font-weight: bold;
    font-size: 1.1em;
    margin-right: 0.75rem;
    flex-shrink: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.checkmark-text {
    flex: 1;
    line-height: 1.5;
    color: var(--text-color);
}

[data-theme="dark"] .checkmark-item {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, transparent 100%);
    border-left-color: var(--button-primary);
}

[data-theme="dark"] .checkmark-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.15) 0%, transparent 100%);
}

[data-theme="dark"] .checkmark {
    color: #4ade80;
}

/* Blockquotes - Professional styling */
.summary-quote {
    margin: 2rem 0;
    padding: 1.5rem 2rem;
    border-left: 4px solid var(--input-focus);
    background: linear-gradient(135deg, rgba(102,126,234,0.08) 0%, rgba(118,75,162,0.05) 100%);
    border-radius: 8px;
    font-style: italic;
    position: relative;
}

.summary-quote::before {
    content: '"';
    font-size: 3rem;
    color: var(--input-focus);
    position: absolute;
    top: 0.5rem;
    left: 1rem;
    opacity: 0.3;
    font-family: Georgia, serif;
}

.summary-quote p {
    margin: 0;
    padding-left: 1rem;
}

/* Code blocks */
.summary-code-block {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    overflow-x: auto;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
}

.summary-code-block code {
    background: none;
    padding: 0;
    border: none;
    font-size: inherit;
}

/* Reading time and cache indicators - Professional styling */
.reading-time {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--reading-time-bg);
    color: var(--reading-time-text);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin: 1rem 0;
    border: 1px solid rgba(25, 118, 210, 0.2);
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.1);
}

.reading-time-icon {
    font-size: 1.2rem;
}

.reading-time-text {
    font-weight: 500;
    font-size: 0.95rem;
}

.cache-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: #0369a1;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin: 1rem 0;
    border: 1px solid rgba(3, 105, 161, 0.2);
    box-shadow: 0 2px 8px rgba(3, 105, 161, 0.1);
}

[data-theme="dark"] .cache-indicator {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: #7dd3fc;
    border-color: rgba(125, 211, 252, 0.2);
}

.cache-icon {
    font-size: 1.2rem;
}

.cache-text {
    font-weight: 500;
    font-size: 0.95rem;
}

.cache-provider {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Headings inside summaries: clear, consistent hierarchy */
#summaryContent h1,
#summaryContent h2,
#summaryContent h3,
#summaryContent h4 {
    color: var(--text-color);
    margin-top: 1.6rem;
    margin-bottom: 0.6rem;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: 0.2px;
}

/* Distinct sizes for heading levels */
#summaryContent h1 { font-size: 2rem; }
#summaryContent h2 { font-size: 1.6rem; }
#summaryContent h3 { font-size: 1.3rem; }
#summaryContent h4 { font-size: 1.05rem; }

/* Make section groups visually connected to headings */
#summaryContent .section,
#summaryContent .chapter,
#summaryContent section {
    padding: 1rem 1.25rem;
    margin: 1rem 0 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(255,255,255,0.98), transparent);
    box-shadow: 0 6px 18px rgba(0,0,0,0.04);
}

/* Lists: clear markers and generous spacing */
#summaryContent ul,
#summaryContent ol {
    margin: 0.75rem 0 1rem 1.25rem;
    padding-left: 1rem;
    color: var(--text-color);
}

#summaryContent li {
    margin-bottom: 0.6rem;
    line-height: 1.6;
}

/* Better visible ordered markers for screen readers + sighted users */
#summaryContent ol { list-style-type: decimal; }
#summaryContent ul { list-style-type: disc; list-style-position: outside; }

/* Definition lists to expose name/value relationships */
#summaryContent dl {
    margin: 0.75rem 0;
}
#summaryContent dt {
    font-weight: 700;
    margin-top: 0.75rem;
}
#summaryContent dd {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
}

/* Quotes: visually grouped and contrasted */
#summaryContent blockquote {
    margin: 1rem 0;
    padding: 1rem 1.25rem;
    border-left: 4px solid var(--reading-time-accent);
    background: rgba(102,126,234,0.04);
    color: var(--text-color);
    border-radius: 6px;
}

/* Figures and captions: preserve relationship */
#summaryContent figure {
    margin: 1rem 0;
}
#summaryContent figcaption {
    font-size: 0.95rem;
    color: var(--text-light);
    background: transparent;
    padding-top: 0.35rem;
}

/* Emphasis for key concept blocks */
#summaryContent .major-section {
    /* Slightly stronger contrast and padding to stand out */
    background: linear-gradient(180deg, rgba(248,249,250,0.9), rgba(233,236,239,0.6));
    color: var(--text-color);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: none;
}

/* Ensure interactive and focusable elements are obvious and keyboard-accessible */
#summaryContent a,
#summaryContent button,
#summaryContent [tabindex]:not([tabindex="-1"]) {
    cursor: pointer;
    transition: box-shadow 0.15s ease, transform 0.08s ease;
}

/* High-visibility focus ring for keyboard users */
#summaryContent a:focus,
#summaryContent button:focus,
#summaryContent [tabindex]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102,126,234,0.18);
    border-radius: 6px;
}

/* Ensure links have sufficient contrast and are underlined by default */
#summaryContent a {
    color: var(--input-focus);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* When printing, keep relationships intact and readable */
@media print {
    #summaryContent {
        color: #000;
        background: transparent;
    }
    #summaryContent .section,
    #summaryContent section {
        border: none;
        box-shadow: none;
        padding: 0;
        margin: 0 0 1rem 0;
    }
}

/* Small-screen adjustments for readability */
@media (max-width: 768px) {
    #summaryContent {
        font-size: 17px;
        padding: 0 0.5rem;
    }
    #summaryContent h1 { font-size: 1.6rem; }
    #summaryContent h2 { font-size: 1.3rem; }
}

/* Accessibility & Professional summary formatting (WCAG 1.3.1 - Info & Relationship) */
/* Applied to #summaryContent and children to make hierarchy, groups and controls visually clear. */

#summaryContent {
	/* Ensure readable line-length and stronger base contrast */
	max-width: 900px;
	margin: 0 auto;
	font-size: 18px;
	line-height: 1.8;
	color: var(--text-color);
}

/* Headings inside summaries: clear, consistent hierarchy */
#summaryContent h1,
#summaryContent h2,
#summaryContent h3,
#summaryContent h4 {
	color: var(--text-color);
	margin-top: 1.6rem;
	margin-bottom: 0.6rem;
	line-height: 1.25;
	font-weight: 800;
	letter-spacing: 0.2px;
}

/* Distinct sizes for heading levels */
#summaryContent h1 { font-size: 2rem; }
#summaryContent h2 { font-size: 1.6rem; }
#summaryContent h3 { font-size: 1.3rem; }
#summaryContent h4 { font-size: 1.05rem; }

/* Make section groups visually connected to headings */
#summaryContent .section,
#summaryContent .chapter,
#summaryContent section {
	padding: 1rem 1.25rem;
	margin: 1rem 0 1.5rem;
	border: 1px solid var(--border-color);
	border-radius: 10px;
	background: linear-gradient(180deg, rgba(255,255,255,0.98), transparent);
	box-shadow: 0 6px 18px rgba(0,0,0,0.04);
}

/* Lists: clear markers and generous spacing */
#summaryContent ul,
#summaryContent ol {
	margin: 0.75rem 0 1rem 1.25rem;
	padding-left: 1rem;
	color: var(--text-color);
}

#summaryContent li {
	margin-bottom: 0.6rem;
	line-height: 1.6;
}

/* Better visible ordered markers for screen readers + sighted users */
#summaryContent ol { list-style-type: decimal; }
#summaryContent ul { list-style-type: disc; list-style-position: outside; }

/* Definition lists to expose name/value relationships */
#summaryContent dl {
	margin: 0.75rem 0;
}
#summaryContent dt {
	font-weight: 700;
	margin-top: 0.75rem;
}
#summaryContent dd {
	margin-left: 1.5rem;
	margin-bottom: 0.5rem;
}

/* Quotes: visually grouped and contrasted */
#summaryContent blockquote {
	margin: 1rem 0;
	padding: 1rem 1.25rem;
	border-left: 4px solid var(--reading-time-accent);
	background: rgba(102,126,234,0.04);
	color: var(--text-color);
	border-radius: 6px;
}

/* Figures and captions: preserve relationship */
#summaryContent figure {
	margin: 1rem 0;
}
#summaryContent figcaption {
	font-size: 0.95rem;
	color: var(--text-light);
	background: transparent;
	padding-top: 0.35rem;
}

/* Emphasis for key concept blocks */
#summaryContent .major-section {
	/* Slightly stronger contrast and padding to stand out */
	background: linear-gradient(180deg, rgba(248,249,250,0.9), rgba(233,236,239,0.6));
	color: var(--text-color);
	padding: 1rem 1.25rem;
	border-radius: 8px;
	box-shadow: none;
}

/* Ensure interactive and focusable elements are obvious and keyboard-accessible */
#summaryContent a,
#summaryContent button,
#summaryContent [tabindex]:not([tabindex="-1"]) {
	cursor: pointer;
	transition: box-shadow 0.15s ease, transform 0.08s ease;
}

/* High-visibility focus ring for keyboard users */
#summaryContent a:focus,
#summaryContent button:focus,
#summaryContent [tabindex]:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(102,126,234,0.18);
	border-radius: 6px;
}

/* Ensure links have sufficient contrast and are underlined by default */
#summaryContent a {
	color: var(--input-focus);
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* When printing, keep relationships intact and readable */
@media print {
	#summaryContent {
		color: #000;
		background: transparent;
	}
	#summaryContent .section,
	#summaryContent section {
		border: none;
		box-shadow: none;
		padding: 0;
		margin: 0 0 1rem 0;
	}
}

/* Small-screen adjustments for readability */
@media (max-width: 768px) {
	#summaryContent {
		font-size: 17px;
		padding: 0 0.5rem;
	}
	#summaryContent h1 { font-size: 1.6rem; }
	#summaryContent h2 { font-size: 1.3rem; }
}

/* Login Page Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-header {
    margin-bottom: 30px;
}

.login-header h1 {
    color: var(--text-color);
    font-size: 2rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.login-header p {
    color: var(--text-light);
    font-size: 0.95rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-color);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.password-container {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
}

.password-toggle:hover {
    color: #333;
}

.remember-me {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 10px 0;
}

.remember-me input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 2px 0 0 0;
    flex-shrink: 0;
    cursor: pointer;
}

.remember-me label {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1.4;
}

/* Checkbox container styling for login page */
.checkbox-container {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-light);
}

.checkbox-container input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 2px 0 0 0;
    flex-shrink: 0;
    cursor: pointer;
}

.checkbox-container .checkmark {
    display: none;
}

.login-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    margin-top: 10px;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.login-btn:active {
    transform: translateY(0);
}

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

.error-message {
    background: var(--error-bg, #fee);
    color: var(--error-color);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--error-border, #fcc);
    font-size: 0.9rem;
    margin-top: 15px;
    display: none;
}

.error-message.show {
    display: block;
    animation: slideIn 0.3s ease;
}

.public-links {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.public-links p {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.public-links a {
    color: var(--link-color);
    text-decoration: none;
    margin: 0 10px;
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.public-links a:hover {
    color: var(--link-hover-color, var(--link-color));
    text-decoration: underline;
}

/* Logout Button Styles */
.logout-btn {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 1000;
    margin-left: 10px;
}

.logout-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.logout-btn:active {
    transform: translateY(0);
}

/* Fixed position for mobile */
@media (max-width: 768px) {
    .logout-btn {
        position: fixed;
        top: 20px;
        right: 20px;
        margin-left: 0;
    }
}

/* Dark theme support for login page */
@media (prefers-color-scheme: dark) {
    .login-card {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .login-header h1 {
        color: #e2e8f0;
    }
    
    .login-header p {
        color: #a0aec0;
    }
    
    .form-group label {
        color: #e2e8f0;
    }
    
    .form-group input {
        background: #4a5568;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .form-group input:focus {
        border-color: #667eea;
        background: #4a5568;
    }
    
    .remember-me label {
        color: #a0aec0;
    }
    
    .public-links {
        border-top-color: #4a5568;
    }
    
    .public-links p {
        color: #a0aec0;
    }
    
    .error-message {
        background: #742a2a;
        color: #fed7d7;
        border-color: #9b2c2c;
    }
}

/* Mobile responsiveness for login page */
@media (max-width: 480px) {
    .login-container {
        padding: 10px;
    }
    
    .login-card {
        padding: 30px 20px;
    }
    
    .login-header h1 {
        font-size: 1.5rem;
    }
    
    .logout-btn {
        position: static;
        margin: 20px auto;
        display: block;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Copy button styling */
.copy-btn {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.copy-btn:hover {
    background: linear-gradient(135deg, #20c997 0%, #28a745 100%);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
    transform: translateY(-1px);
}

.copy-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

/* Dark theme for copy button */
[data-theme="dark"] .copy-btn {
    background: linear-gradient(135deg, #38d9a9 0%, #20c997 100%);
    box-shadow: 0 2px 4px rgba(56, 217, 169, 0.4);
}

[data-theme="dark"] .copy-btn:hover {
    background: linear-gradient(135deg, #20c997 0%, #38d9a9 100%);
    box-shadow: 0 4px 12px rgba(56, 217, 169, 0.5);
}

/* Copy success message animations */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

/* Mobile responsiveness for summary actions */
@media (max-width: 768px) {
    .summary-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .action-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Footer Styles */
.footer {
    background: var(--card-background);
    border-top: 1px solid var(--card-background);
    padding: 2rem 0;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    text-align: center;
}

.footer-links {
    margin-bottom: 1rem;
}

.footer-link {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

.footer-link:hover {
    color: var(--primary-color);
    background: var(--input-background);
}

.footer-separator {
    color: var(--text-secondary);
    margin: 0 0.5rem;
}

.footer-copyright {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer-copyright p {
    margin: 0;
}

/* Legal Pages Styles */
.legal-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
}

.legal-page h1 {
    color: var(--text-color);
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.last-updated {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.legal-section {
    margin-bottom: 2rem;
}

.legal-section h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-color);
}

.legal-section p {
    color: var(--text-color);
    line-height: 1.6;
    margin-bottom: 1rem;
}

.legal-section ul {
    color: var(--text-color);
    line-height: 1.6;
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.legal-section li {
    margin-bottom: 0.5rem;
}

.legal-section strong {
    color: var(--primary-color);
    font-weight: 600;
}

/* Logo link styling for legal pages */
.logo-link {
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

.logo-link:hover {
    color: var(--primary-color);
}

/* Mobile responsiveness for legal pages */
@media (max-width: 768px) {
    .legal-page {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .legal-page h1 {
        font-size: 2rem;
    }
    
    .legal-section h2 {
        font-size: 1.3rem;
    }
    
    .footer {
        padding: 1.5rem 0;
    }
    
    .footer-links {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .footer-separator {
        display: none;
    }
}

/* Cache Panel Styles */
.cache-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: var(--card-bg);
    border-left: 1px solid var(--border-color);
    z-index: 2000;
    transition: right 0.3s ease;
    overflow-y: auto;
    box-shadow: -4px 0 20px var(--shadow);
}

.cache-panel.active {
    right: 0;
}

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

.cache-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-cache {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.close-cache:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cache-content {
    padding: 1rem;
}

.cache-info {
    margin-bottom: 1.5rem;
}

.cache-description {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    color: var(--text-color);
    opacity: 0.8;
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 1rem;
}

.cache-stats {
    display: flex;
    justify-content: space-between;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.9rem;
}

.cache-count, .cache-size {
    color: var(--text-color);
    font-weight: 500;
}

.cache-list {
    margin-bottom: 2rem;
    max-height: 400px;
    overflow-y: auto;
}

.no-cache {
    text-align: center;
    color: var(--text-color);
    opacity: 0.7;
    padding: 2rem;
    font-style: italic;
}

.cache-item {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.cache-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-hover);
}

.cache-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.cache-item-title {
    font-weight: 600;
    color: var(--text-color);
    margin: 0;
    font-size: 0.95rem;
}

.cache-item-date {
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.7;
}

.cache-item-author {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.cache-item-size {
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.cache-item-actions {
    display: flex;
    gap: 0.5rem;
}

.cache-load-btn, .cache-delete-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.cache-load-btn:hover {
    background: var(--input-focus);
    color: white;
    border-color: var(--input-focus);
}

.cache-delete-btn:hover {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

.cache-actions {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

.refresh-cache-btn, .clear-cache-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.refresh-cache-btn {
    background: var(--input-focus);
    color: white;
}

.refresh-cache-btn:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
}

.clear-cache-btn {
    background: var(--error-color);
    color: white;
}

.clear-cache-btn:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* ...existing code... */

/* Accessibility & Professional summary formatting (WCAG 1.3.1 - Info & Relationship) */
/* Applied to #summaryContent and children to make hierarchy, groups and controls visually clear. */

#summaryContent {
	/* Ensure readable line-length and stronger base contrast */
	max-width: 900px;
	margin: 0 auto;
	font-size: 18px;
	line-height: 1.8;
	color: var(--text-color);
}

/* Headings inside summaries: clear, consistent hierarchy */
#summaryContent h1,
#summaryContent h2,
#summaryContent h3,
#summaryContent h4 {
	color: var(--text-color);
	margin-top: 1.6rem;
	margin-bottom: 0.6rem;
	line-height: 1.25;
	font-weight: 800;
	letter-spacing: 0.2px;
}

/* Distinct sizes for heading levels */
#summaryContent h1 { font-size: 2rem; }
#summaryContent h2 { font-size: 1.6rem; }
#summaryContent h3 { font-size: 1.3rem; }
#summaryContent h4 { font-size: 1.05rem; }

/* Make section groups visually connected to headings */
#summaryContent .section,
#summaryContent .chapter,
#summaryContent section {
	padding: 1rem 1.25rem;
	margin: 1rem 0 1.5rem;
	border: 1px solid var(--border-color);
	border-radius: 10px;
	background: linear-gradient(180deg, rgba(255,255,255,0.98), transparent);
	box-shadow: 0 6px 18px rgba(0,0,0,0.04);
}

/* Lists: clear markers and generous spacing */
#summaryContent ul,
#summaryContent ol {
	margin: 0.75rem 0 1rem 1.25rem;
	padding-left: 1rem;
	color: var(--text-color);
}

#summaryContent li {
	margin-bottom: 0.6rem;
	line-height: 1.6;
}

/* Better visible ordered markers for screen readers + sighted users */
#summaryContent ol { list-style-type: decimal; }
#summaryContent ul { list-style-type: disc; list-style-position: outside; }

/* Definition lists to expose name/value relationships */
#summaryContent dl {
	margin: 0.75rem 0;
}
#summaryContent dt {
	font-weight: 700;
	margin-top: 0.75rem;
}
#summaryContent dd {
	margin-left: 1.5rem;
	margin-bottom: 0.5rem;
}

/* Quotes: visually grouped and contrasted */
#summaryContent blockquote {
	margin: 1rem 0;
	padding: 1rem 1.25rem;
	border-left: 4px solid var(--reading-time-accent);
	background: rgba(102,126,234,0.04);
	color: var(--text-color);
	border-radius: 6px;
}

/* Figures and captions: preserve relationship */
#summaryContent figure {
	margin: 1rem 0;
}
#summaryContent figcaption {
	font-size: 0.95rem;
	color: var(--text-light);
	background: transparent;
	padding-top: 0.35rem;
}

/* Emphasis for key concept blocks */
#summaryContent .major-section {
	/* Slightly stronger contrast and padding to stand out */
	background: linear-gradient(180deg, rgba(248,249,250,0.9), rgba(233,236,239,0.6));
	color: var(--text-color);
	padding: 1rem 1.25rem;
	border-radius: 8px;
	box-shadow: none;
}

/* Ensure interactive and focusable elements are obvious and keyboard-accessible */
#summaryContent a,
#summaryContent button,
#summaryContent [tabindex]:not([tabindex="-1"]) {
	cursor: pointer;
	transition: box-shadow 0.15s ease, transform 0.08s ease;
}

/* High-visibility focus ring for keyboard users */
#summaryContent a:focus,
#summaryContent button:focus,
#summaryContent [tabindex]:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(102,126,234,0.18);
	border-radius: 6px;
}

/* Ensure links have sufficient contrast and are underlined by default */
#summaryContent a {
	color: var(--input-focus);
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* When printing, keep relationships intact and readable */
@media print {
	#summaryContent {
		color: #000;
		background: transparent;
	}
	#summaryContent .section,
	#summaryContent section {
		border: none;
		box-shadow: none;
		padding: 0;
		margin: 0 0 1rem 0;
	}
}

/* Small-screen adjustments for readability */
@media (max-width: 768px) {
	#summaryContent {
		font-size: 17px;
		padding: 0 0.5rem;
	}
	#summaryContent h1 { font-size: 1.6rem; }
	#summaryContent h2 { font-size: 1.3rem; }
}
