:root {
    --bg-color: #ffffff;
    --text-color: #2d2d2d;
    --sidebar-bg: #f8f9fa;
    --border-color: #e9ecef;
    --highlight-color: #fff3cd;
    --accent-color: #333;
    --popover-bg: #ffffff;
    --popover-shadow: 0 4px 12px rgba(0,0,0,0.15);
    --font-size-multiplier: 1;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --sidebar-bg: #2d2d2d;
    --border-color: #404040;
    --highlight-color: #4a4a2e;
    --accent-color: #f0f0f0;
    --popover-bg: #2d2d2d;
    --popover-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

body {
    font-family: 'Merriweather', serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
}

.app-container {
    position: relative;
    overflow-x: visible;
}

/* Toolbar */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 100;
    pointer-events: auto;
}

.toolbar-left {
    display: flex !important;
    align-items: center;
    flex: 1;
    min-width: 0;
    order: 1;
    justify-content: flex-start;
    pointer-events: auto !important;
    position: relative;
    z-index: 102 !important;
}

.toolbar-right {
    order: 2;
    display: flex;
    align-items: center;
}

.book-title {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--text-color);
    background: linear-gradient(120deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.book-title.clickable {
    cursor: pointer;
}

.book-title.clickable:hover {
    background: linear-gradient(120deg, rgba(99, 102, 241, 0.25) 0%, rgba(139, 92, 246, 0.25) 100%);
    transform: translateY(-1px);
}

[data-theme="dark"] .book-title {
    background: linear-gradient(120deg, rgba(99, 102, 241, 0.25) 0%, rgba(139, 92, 246, 0.25) 100%);
}

[data-theme="dark"] .book-title.clickable:hover {
    background: linear-gradient(120deg, rgba(99, 102, 241, 0.35) 0%, rgba(139, 92, 246, 0.35) 100%);
}

.page-indicator {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    color: var(--text-color);
    margin-left: 1rem;
    opacity: 0.7;
    text-decoration: none;
}

.page-indicator.clickable {
    cursor: pointer;
    transition: opacity 0.2s;
}

.page-indicator.clickable:hover {
    opacity: 1;
}

.chapter-title {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text-color);
    margin-left: 1rem;
    opacity: 0.6;
    font-style: italic;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-title.clickable {
    cursor: pointer;
    transition: opacity 0.2s;
}

.chapter-title.clickable:hover {
    opacity: 1;
}

.toc-toggle-left {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    margin-right: 1rem;
    margin-left: 0 !important;
    border-radius: 4px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    order: -1 !important;
    flex-shrink: 0;
    position: relative;
    left: 0 !important;
    pointer-events: auto !important;
    z-index: 102 !important;
    touch-action: manipulation;
}

.toc-toggle-left:hover {
    background-color: var(--border-color);
}

.toolbar-right button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px;
    margin-left: 8px;
    border-radius: 4px;
    pointer-events: auto !important;
    position: relative;
    z-index: 102 !important;
    touch-action: manipulation;
}

.toolbar-right button:hover {
    background-color: var(--border-color);
}

/* Main Content */
.content {
    margin-top: 60px;
    padding: 2rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    min-height: calc(100vh - 60px);
    padding-bottom: 6rem; /* Extra space for pagination */
    transition: margin-left 0.3s ease;
    position: relative;
    overflow: visible;
}

/* Ensure canvas doesn't affect content height */
.content #annotation-canvas {
    position: absolute;
    top: 2rem;
    left: 2rem;
    right: auto;
    bottom: auto;
}

/* Title Page */
.title-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 4rem 2rem;
    margin-top: 0;
}

.title-page-content {
    text-align: center;
    max-width: 900px;
    width: 100%;
}

.version-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.version-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6366f1;
    opacity: 0.9;
}

.version-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

[data-theme="dark"] .version-badge {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    border-color: rgba(129, 140, 248, 0.4);
}

[data-theme="dark"] .version-label {
    color: #818cf8;
}

[data-theme="dark"] .version-title {
    background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.title-page .main-title {
    font-family: 'Merriweather', serif;
    font-size: 4.5rem;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 3rem;
    line-height: 1.1;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    background: linear-gradient(135deg, #1a1a1a 0%, #4a5568 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

[data-theme="dark"] .title-page .main-title {
    background: linear-gradient(135deg, #e8e8e8 0%, #cbd5e0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.title-page-text {
    font-family: 'Merriweather', serif;
    font-size: 1.2rem;
    line-height: 2;
    color: var(--text-color);
}

.title-page-text p {
    margin: 1rem 0;
}

.title-page-text .authors {
    font-size: 1.4rem;
    font-weight: 400;
    color: #2d3748;
    margin-top: 2rem;
    margin-bottom: 2rem;
    font-style: italic;
}

[data-theme="dark"] .title-page-text .authors {
    color: #e2e8f0;
}

.title-page-text .original-title {
    font-size: 1.5rem;
    font-style: italic;
    color: #2d3748;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

[data-theme="dark"] .title-page-text .original-title {
    color: #e2e8f0;
}

.title-page-text .title-meta {
    font-size: 1rem;
    color: var(--text-color);
    opacity: 0.8;
    margin: 0.75rem 0;
}

@media (max-width: 768px) {
    .title-page .main-title {
        font-size: 3rem;
    }
    
    .title-page-text {
        font-size: 1rem;
    }
    
    .title-page-text .authors {
        font-size: 1.2rem;
    }
    
    .title-page-text .original-title {
        font-size: 1.3rem;
    }
}

.toc-sidebar.open ~ .content {
    margin-left: 300px;
}

@media (max-width: 1024px) {
    .toc-sidebar.open ~ .content {
        margin-left: 0;
    }
}

.text-container {
    max-width: 100%;
}

.text-container p {
    margin-bottom: 1.5rem;
    text-align: justify;
    line-height: 1.8;
    font-size: calc(1.05rem * var(--font-size-multiplier));
}

.text-container p:first-of-type {
    margin-top: 0;
}

/* Markdown styling */
.text-container h1 {
    font-size: calc(2.5rem * var(--font-size-multiplier));
    font-weight: 700;
    margin-top: 3rem;
    margin-bottom: 2rem;
    line-height: 1.2;
    color: var(--accent-color);
    font-family: 'Inter', sans-serif;
    scroll-margin-top: 80px;
}

.text-container h2 {
    font-size: calc(2rem * var(--font-size-multiplier));
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 1.5rem;
    line-height: 1.3;
    color: var(--accent-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.75rem;
    font-family: 'Inter', sans-serif;
    scroll-margin-top: 80px;
}

.text-container h3 {
    font-size: calc(1.75rem * var(--font-size-multiplier));
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 1rem;
    line-height: 1.4;
    color: var(--accent-color);
    font-family: 'Inter', sans-serif;
    scroll-margin-top: 80px;
    position: relative;
}

.text-container h3::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 1.5rem;
    background: var(--accent-color);
    opacity: 0.3;
    border-radius: 2px;
}

.text-container h4 {
    font-size: calc(1.35rem * var(--font-size-multiplier));
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
    color: var(--accent-color);
    font-family: 'Inter', sans-serif;
    scroll-margin-top: 80px;
}

.text-container h5, .text-container h6 {
    font-size: calc(1.1rem * var(--font-size-multiplier));
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    color: var(--accent-color);
}

.text-container ul, .text-container ol {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

.text-container li {
    margin-bottom: 0.75rem;
    line-height: 1.8;
}

.text-container ul li {
    list-style-type: disc;
}

.text-container ol li {
    list-style-type: decimal;
}

.text-container ul ul, .text-container ol ol {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.text-container blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1.5rem;
    margin: 2rem 0;
    font-style: italic;
    color: var(--text-color);
    opacity: 0.85;
    background-color: var(--sidebar-bg);
    padding: 1rem 1.5rem;
    border-radius: 0 4px 4px 0;
}

.text-container code {
    background-color: var(--sidebar-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.text-container pre {
    background-color: var(--sidebar-bg);
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1.5rem 0;
}

.text-container pre code {
    background-color: transparent;
    padding: 0;
}

.text-container strong {
    font-weight: 700;
    color: var(--accent-color);
}

.text-container em {
    font-style: italic;
}

.text-container a {
    color: var(--accent-color);
    text-decoration: underline;
}

.text-container a:hover {
    opacity: 0.8;
}

.text-container hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

.text-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.text-container th, .text-container td {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.text-container th {
    background-color: var(--sidebar-bg);
    font-weight: 600;
}

/* Page number markers */
.text-container [data-page] {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.6;
    margin: 1rem 0;
    font-weight: 500;
}

/* TOC Sidebar */
.toc-sidebar {
    position: fixed;
    left: -320px;
    top: 60px;
    width: 300px;
    height: calc(100vh - 60px);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    transition: left 0.3s ease;
    z-index: 90;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
}

.toc-sidebar.open {
    left: 0;
}

.toc-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.toc-header h3 {
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-color);
}

.toc-header button {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.toc-header button:hover {
    background-color: var(--border-color);
}

.toc-nav {
    padding: 1rem;
}

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

.toc-nav .toc-list li {
    margin-bottom: 0.5rem;
}

.toc-nav .toc-list a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9rem;
    line-height: 1.4;
}

.toc-nav .toc-list a:hover {
    background-color: var(--border-color);
    color: var(--accent-color);
}

.toc-nav .toc-list a.active {
    background-color: var(--accent-color);
    color: var(--bg-color);
    font-weight: 500;
}

/* Expandable TOC Chapters */
.toc-chapter {
    margin-bottom: 0.5rem;
}

.toc-chapter-header {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.toc-expand {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: transform 0.2s, background-color 0.2s;
    flex-shrink: 0;
    opacity: 0.6;
}

.toc-expand:hover {
    background-color: var(--border-color);
    opacity: 1;
}

.toc-expand-icon {
    transition: transform 0.2s;
}

.toc-chapter.expanded .toc-expand-icon {
    transform: rotate(90deg);
}

.toc-chapter-link {
    flex: 1;
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9rem;
    line-height: 1.4;
}

.toc-chapter-link:hover {
    background-color: var(--border-color);
    color: var(--accent-color);
}

.toc-subsections {
    list-style: none;
    padding: 0;
    margin: 0;
    margin-left: 1.5rem;
    margin-top: 0.25rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.toc-chapter.expanded .toc-subsections {
    max-height: 2000px;
    transition: max-height 0.3s ease-in;
}

.toc-subsections li {
    margin-bottom: 0.25rem;
}

.toc-subsections a {
    display: block;
    padding: 0.4rem 0.75rem;
    color: var(--text-color);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.85rem;
    line-height: 1.4;
    opacity: 0.85;
}

.toc-subsections a:hover {
    background-color: var(--border-color);
    color: var(--accent-color);
    opacity: 1;
}

.toc-subsections a.active {
    background-color: var(--accent-color);
    color: var(--bg-color);
    font-weight: 500;
    opacity: 1;
}

/* Chapter Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3rem;
    padding-top: 2rem;
    padding-bottom: 2rem;
    border-top: 1px solid var(--border-color);
    font-family: 'Inter', sans-serif;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-link:hover {
    background-color: var(--border-color);
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.nav-link.prev {
    margin-right: auto;
}

.nav-link.next {
    margin-left: auto;
}

.nav-link svg {
    flex-shrink: 0;
}

/* Pagination */
.pagination {
    display: flex !important;
    justify-content: center;
    gap: 20px;
    align-items: center;
    margin-top: 3rem;
    padding-top: 2rem;
    padding-bottom: 4rem;
    border-top: 1px solid var(--border-color);
    font-family: 'Inter', sans-serif;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
    z-index: 1;
}

.nav-btn {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
    display: inline-block;
}

.nav-btn:hover:not(.disabled) {
    background-color: var(--border-color);
}

.nav-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: transparent;
    pointer-events: none;
}

.page-display {
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
}

/* Define Button */
.define-btn {
    position: absolute;
    background: var(--accent-color);
    color: var(--bg-color);
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    z-index: 200;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.define-btn::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: var(--accent-color) transparent transparent transparent;
}

/* Popover */
.define-popover {
    position: fixed; /* Simplified to fixed for demo, usually absolute near text */
    bottom: 20px;
    right: 360px; /* Space for chat */
    width: 300px;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--popover-shadow);
    z-index: 900;
    padding: 1rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
}
.hidden { display: none !important; }

.popover-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.popover-header button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
}

/* Sidebar */
.chat-sidebar {
    position: fixed;
    top: 60px;
    right: -350px; /* Start hidden off-screen */
    bottom: 0;
    width: 350px !important;
    min-width: 350px !important;
    max-width: 350px !important;
    background: var(--sidebar-bg) !important;
    border-left: 1px solid var(--border-color);
    transition: right 0.3s ease;
    z-index: 9999 !important;
    display: flex !important;
    flex-direction: column;
    box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    visibility: visible !important;
    opacity: 1 !important;
    overflow: visible;
}

.chat-sidebar.open {
    right: 0 !important;
}

.chat-sidebar.collapsed {
    right: -350px !important;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'Inter', sans-serif;
}

.chat-header h2 { font-size: 1rem; margin: 0; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
}

.message {
    margin-bottom: 1rem;
    padding: 0.8rem;
    border-radius: 8px;
    max-width: 90%;
}

.message.user {
    background: #007bff;
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.message.system {
    background: var(--border-color);
    color: var(--text-color);
}

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

#chat-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    resize: none;
}

#send-chat {
    background: var(--accent-color);
    color: var(--bg-color);
    border: none;
    border-radius: 4px;
    width: 32px;
    cursor: pointer;
}

/* Font Menu */
.font-menu {
    position: fixed;
    top: 65px;
    right: 80px;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: var(--popover-shadow);
    z-index: 110;
    font-family: 'Inter', sans-serif;
    min-width: 200px;
}

.font-option {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.font-controls button {
    padding: 2px 8px;
    cursor: pointer;
    background: var(--border-color);
    border: none;
    border-radius: 4px;
    color: var(--text-color);
}

/* Search Bar */
.search-bar {
    position: fixed;
    top: 65px;
    right: 120px;
    background: var(--popover-bg);
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--popover-shadow);
    z-index: 110;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    min-width: 300px;
}

#search-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
}

#search-input:focus {
    border-color: var(--accent-color);
}

#search-next,
#search-prev,
#search-close {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 32px;
}

#search-next:hover,
#search-prev:hover,
#search-close:hover {
    background: var(--sidebar-bg);
}

#search-stats {
    font-size: 0.85rem;
    color: var(--text-color);
    opacity: 0.7;
    white-space: nowrap;
}


/* Helper to ignore pointer events on icons for cleaner clicks */
button svg {
    pointer-events: none;
}

/* Annotation Canvas Overlay */
#annotation-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 50;
    display: none;
    visibility: hidden;
    margin: 0;
    padding: 0;
    border: none;
    outline: none;
    background: transparent;
}

#annotation-canvas.annotation-active {
    pointer-events: auto;
    display: block;
    visibility: visible;
}

#annotation-canvas.annotation-active {
    pointer-events: auto;
}

/* Annotation Toolbar */
.annotation-toolbar {
    position: fixed;
    top: 70px;
    right: 20px;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: var(--popover-shadow);
    z-index: 200;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Inter', sans-serif;
}

.annotation-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    min-width: 36px;
    min-height: 36px;
}

.annotation-btn:hover {
    background-color: var(--border-color);
}

.annotation-btn.active {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
}

.annotation-separator {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 0.25rem;
}

#annotation-color {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

#annotation-width {
    width: 80px;
    cursor: pointer;
}

#annotation-width-display {
    font-size: 0.85rem;
    color: var(--text-color);
    min-width: 35px;
    text-align: center;
}

.annotation-toggle-btn {
    background-color: var(--accent-color);
    color: var(--bg-color);
}

.annotation-toggle-btn:hover {
    opacity: 0.9;
}

@media (max-width: 768px) {
    .annotation-toolbar {
        top: 70px;
        right: 10px;
        flex-wrap: wrap;
        max-width: calc(100vw - 20px);
    }
    
    .annotation-sidebar {
        width: 100%;
    }
}

/* SVG Overlay for Drawing */
#annotation-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: none; /* Hidden by default, shown when in draw mode */
}

#annotation-svg-overlay path {
    cursor: pointer;
}

/* Annotation Note Popup */
.annotation-note-popup {
    position: fixed;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--popover-shadow);
    z-index: 300;
    min-width: 300px;
    max-width: 400px;
}

.annotation-note-popup.hidden {
    display: none;
}

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

.annotation-note-header span {
    font-weight: 600;
    color: var(--text-color);
}

.annotation-note-header button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-note-header button:hover {
    background-color: var(--border-color);
    border-radius: 4px;
}

#annotation-note-text {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    box-sizing: border-box;
}

.annotation-note-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
}

.annotation-note-actions button {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.annotation-note-actions button:hover {
    background-color: var(--border-color);
}

.annotation-note-actions button:first-child {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
}

/* Annotation Sidebar */
.annotation-sidebar {
    position: fixed;
    top: 60px;
    right: 0;
    width: 350px;
    height: calc(100vh - 60px);
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    z-index: 150;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.annotation-sidebar.hidden {
    display: none;
}

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

.annotation-sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-color);
}

.annotation-sidebar-header button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-sidebar-header button:hover {
    background-color: var(--border-color);
    border-radius: 4px;
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.annotation-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.annotation-item:hover {
    background-color: var(--border-color);
}

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

.annotation-type {
    font-size: 1.2rem;
}

.annotation-item-delete {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.annotation-item-delete:hover {
    opacity: 1;
    background-color: var(--border-color);
    border-radius: 4px;
}

.annotation-item-text {
    color: var(--text-color);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.annotation-item-note {
    color: var(--text-color);
    font-size: 0.85rem;
    font-style: italic;
    opacity: 0.8;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

/* Annotation Highlights */
.annotation-highlight {
    background-color: rgba(255, 255, 0, 0.3) !important;
    cursor: pointer;
    transition: background-color 0.2s;
}

.annotation-highlight:hover {
    background-color: rgba(255, 255, 0, 0.5) !important;
}

/* Annotation Note Popup */
.annotation-note-popup {
    position: fixed;
    background: var(--popover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--popover-shadow);
    z-index: 300;
    min-width: 300px;
    max-width: 400px;
}

.annotation-note-popup.hidden {
    display: none;
}

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

.annotation-note-header span {
    font-weight: 600;
    color: var(--text-color);
}

.annotation-note-header button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-note-header button:hover {
    background-color: var(--border-color);
    border-radius: 4px;
}

#annotation-note-text {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    box-sizing: border-box;
}

.annotation-note-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
}

.annotation-note-actions button {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}

.annotation-note-actions button:hover {
    background-color: var(--border-color);
}

.annotation-note-actions button:first-child {
    background-color: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
}

/* Annotation Sidebar */
.annotation-sidebar {
    position: fixed;
    top: 60px;
    right: 0;
    width: 350px;
    height: calc(100vh - 60px);
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    z-index: 150;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.annotation-sidebar.hidden {
    display: none;
}

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

.annotation-sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-color);
}

.annotation-sidebar-header button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.annotation-sidebar-header button:hover {
    background-color: var(--border-color);
    border-radius: 4px;
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.annotation-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.annotation-item:hover {
    background-color: var(--border-color);
}

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

.annotation-type {
    font-size: 1.2rem;
}

.annotation-item-delete {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.annotation-item-delete:hover {
    opacity: 1;
    background-color: var(--border-color);
    border-radius: 4px;
}

.annotation-item-text {
    color: var(--text-color);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.annotation-item-note {
    color: var(--text-color);
    font-size: 0.85rem;
    font-style: italic;
    opacity: 0.8;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

/* Annotation Highlights */
.annotation-highlight {
    background-color: rgba(255, 255, 0, 0.3) !important;
    cursor: pointer;
    transition: background-color 0.2s;
}

.annotation-highlight:hover {
    background-color: rgba(255, 255, 0, 0.5) !important;
}

/* Selection highlighting for search */
mark {
    background-color: #ffeb3b;
    color: black;
}
[data-theme="dark"] mark {
    background-color: #a39000;
    color: white;
}

/* Search highlight styling */
.search-highlight {
    background-color: #ffeb3b;
    color: #000;
    padding: 2px 0;
    border-radius: 2px;
    font-weight: 500;
    animation: highlight-fade 0.3s ease-in;
}

[data-theme="dark"] .search-highlight {
    background-color: #ffd700;
    color: #000;
}

@keyframes highlight-fade {
    from {
        background-color: #ff9800;
    }
    to {
        background-color: #ffeb3b;
    }
}

[data-theme="dark"] @keyframes highlight-fade {
    from {
        background-color: #ffd700;
    }
    to {
        background-color: #ffd700;
    }
}

/* Login Page Styles */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background-color: var(--bg-color);
    transition: background-color 0.3s;
}

.login-container {
    width: 100%;
    max-width: 500px;
    text-align: center;
}

.login-header {
    margin-bottom: 3rem;
}

.login-title {
    font-family: 'Merriweather', serif;
    font-size: 3.5rem;
    font-weight: 700;
    margin: 1.5rem 0 0.5rem;
    line-height: 1.1;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #1a1a1a 0%, #4a5568 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

[data-theme="dark"] .login-title {
    background: linear-gradient(135deg, #e8e8e8 0%, #cbd5e0 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-color);
    opacity: 0.7;
    margin: 0 0 1rem;
}

.login-authors {
    font-family: 'Merriweather', serif;
    font-size: 1.1rem;
    font-style: italic;
    color: var(--text-color);
    opacity: 0.8;
    margin: 0;
}

.login-form-container {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s;
}

[data-theme="dark"] .login-form-container {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--border-color);
}

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

.login-error {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    background-color: #fee2e2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    animation: slideIn 0.3s ease-out;
}

[data-theme="dark"] .login-error {
    background-color: rgba(220, 38, 38, 0.2);
    border-color: rgba(220, 38, 38, 0.3);
    color: #fca5a5;
}

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

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    opacity: 0.9;
}

.form-input {
    width: 100%;
    padding: 0.875rem 1.25rem;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    color: var(--text-color);
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

[data-theme="dark"] .form-input:focus {
    border-color: #818cf8;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.2);
}

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

.login-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
}

.login-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

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

.login-button svg {
    transition: transform 0.2s;
}

.login-button:hover svg {
    transform: translateX(4px);
}

.login-help {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.login-help p {
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-color);
    opacity: 0.7;
    margin: 0;
}

@media (max-width: 768px) {
    .login-title {
        font-size: 2.5rem;
    }
    
    .login-subtitle {
        font-size: 0.8rem;
    }
    
    .login-authors {
        font-size: 1rem;
    }
    
    .login-form-container {
        padding: 2rem 1.5rem;
    }
    
    .login-page {
        padding: 1rem;
    }
}
