/* eBook-specific enhancements */

/* Educational enhancement styles */
.learning-objectives {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid #0284c7;
    border-radius: 12px;
    padding: 1rem;
    margin: 1.2rem 0;
    position: relative;
}

.learning-objectives::before {
    content: "🎯";
    position: absolute;
    top: -12px;
    left: 20px;
    background: white;
    padding: 0 8px;
    font-size: 1.2rem;
}

/* Navigation hints and flags */
.nav-hint {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid #f59e0b;
    padding: 0.7rem;
    margin: 0.7rem 0;
    border-radius: 0 8px 8px 0;
    font-size: 0.9rem;
}

.nav-hint.prerequisite {
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border-left-color: #666666;
}

.nav-hint.advanced {
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
    border-left-color: #555555;
}

.nav-hint.performance {
    background: linear-gradient(135deg, #f8f8f8 0%, #e8e8e8 100%);
    border-left-color: #666666;
}

/* Did you know boxes */
.did-you-know {
    background: linear-gradient(135deg, #f8f8f8 0%, #f0f0f0 100%);
    border: 2px solid #3b82f6;
    border-radius: 12px;
    padding: 1rem;
    margin: 1.2rem 0;
    position: relative;
    font-style: italic;
}

.did-you-know::before {
    content: "💡 Did You Know?";
    position: absolute;
    top: -12px;
    left: 20px;
    background: white;
    padding: 0 8px;
    font-weight: bold;
    color: #333333;
    font-style: normal;
}

/* Historical trivia boxes */
.historical-trivia {
    background: linear-gradient(135deg, #f8f8f8 0%, #f0f0f0 100%);
    border: 2px solid #888888;
    border-radius: 12px;
    padding: 1rem;
    margin: 1.2rem 0;
    position: relative;
}

.historical-trivia::before {
    content: "📜 Historical Trivia";
    position: absolute;
    top: -12px;
    left: 20px;
    background: white;
    padding: 0 8px;
    font-weight: bold;
    color: #333333;
}

/* Cross-reference links */
.see-also {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.7rem;
    margin: 0.7rem 0;
    font-size: 0.9rem;
}

.see-also::before {
    content: "🔗 See Also: ";
    font-weight: bold;
    color: #333333;
}

.see-also a {
    color: #333333;
    text-decoration: none;
    font-weight: 500;
}

.see-also a:hover {
    text-decoration: underline;
}

/* Performance analysis annotations */
.perf-annotation {
    background: #f0f0f0;
    color: #333333;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 0.3rem;
}

.perf-annotation.cycles {
    background: #e8e8e8;
    color: #333333;
}

.perf-annotation.memory {
    background: #f0f0f0;
    color: #333333;
}

.perf-annotation.decision {
    background: #e8e8e8;
    color: #333333;
}

/* Code explanation enhancements */
.code-explanation {
    background: #f8f8f8;
    border-left: 4px solid #666666;
    padding: 0.7rem;
    margin: 0.7rem 0;
    font-size: 0.9rem;
}

.code-explanation .pros {
    color: #333333;
}

.code-explanation .cons {
    color: #333333;
}

.code-explanation .pros::before {
    content: "✅ ";
}

.code-explanation .cons::before {
    content: "🔴 ";
}

/* Exercise sections */
.exercises {
    background: #fafafa;
    border: 2px solid #e5e5e5;
    border-radius: 12px;
    padding: 1.2rem;
    margin: 2rem 0;
}

.exercise-category {
    margin: 1.2rem 0;
}

.exercise-category h3 {
    color: #333333;
    border-bottom: 2px solid #666666;
    padding-bottom: 0.5rem;
}

.exercise-difficulty {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
    margin-right: 0.5rem;
}

.exercise-difficulty.beginner {
    background: #e8e8e8;
    color: #333333;
}

.exercise-difficulty.intermediate {
    background: #f0f0f0;
    color: #333333;
}

.exercise-difficulty.advanced {
    background: #e0e0e0;
    color: #333333;
}

/* Chapter summary boxes */
.chapter-summary {
    background: linear-gradient(135deg, #f8f8f8 0%, #f0f0f0 100%);
    border: 2px solid #888888;
    border-radius: 12px;
    padding: 1.2rem;
    margin: 2rem 0;
}

.chapter-summary h3 {
    color: #333333;
    margin-top: 0;
}

.summary-section {
    margin: 1rem 0;
}

.summary-section ul {
    list-style: none;
    padding-left: 0;
}

.summary-section li::before {
    content: "✅ ";
    color: #333333;
    font-weight: bold;
}

/* Reading experience enhancements */
.ebook-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-header {
    position: sticky;
    top: 0;
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    z-index: 100;
}

.page-breadcrumb {
    font-size: 0.9rem;
    color: var(--accent-color);
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

/* Enhanced typography for book-like reading */
.chapter-content {
    font-feature-settings: 
        "kern" 1,
        "liga" 1,
        "calt" 1,
        "pnum" 1,
        "tnum" 0,
        "onum" 1,
        "lnum" 0,
        "dlig" 0;
    
    /* Better justification */
    text-align: justify;
    text-justify: inter-word;
}

.chapter-content p:first-child:first-letter {
    /* Drop cap for chapter beginnings */
    float: left;
    font-size: 4rem;
    line-height: 3rem;
    padding: 0.5rem 0.5rem 0 0;
    margin: 0.2rem 0.3rem 0 0;
    font-weight: bold;
    color: var(--accent-color);
}

/* Enhanced headings */
.chapter-content h1::before {
    content: "";
    display: block;
    width: 100px;
    height: 3px;
    background-color: var(--accent-color);
    margin-bottom: 1rem;
}

.chapter-content h2 {
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* Code block enhancements */
.code-block {
    position: relative;
    margin: 2rem 0;
}

.code-block::before {
    content: "FASM Code";
    position: absolute;
    top: -0.5rem;
    left: 1rem;
    background-color: var(--bg-color);
    padding: 0 0.5rem;
    font-size: 0.8rem;
    color: var(--accent-color);
    font-weight: 600;
}

.code-block pre {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    position: relative;
}

/* Enhanced interactive code blocks */
.interactive-code-block {
    position: relative;
    margin: 2rem 0;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.interactive-code-block:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.code-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.code-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.code-language {
    color: var(--accent-color);
    font-family: 'Courier New', monospace;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.code-copy,
.code-download {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--accent-color);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    gap: 0.25rem;
}

.code-copy:hover,
.code-download:hover {
    background: var(--accent-color);
    color: var(--bg-color);
    transform: scale(1.05);
}

.code-copy:active,
.code-download:active {
    transform: scale(0.95);
}

.interactive-code-block pre {
    margin: 0;
    border: none;
    border-radius: 0;
    background: #2d3748; /* Dark gray background */
    color: #e2e8f0; /* Light gray text */
    padding: 1.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Clickable assembly instructions */
.clickable-instruction {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    transition: all 0.2s ease;
}

.clickable-instruction:hover {
    background-color: rgba(0, 102, 204, 0.1);
    border-radius: 3px;
    padding: 1px 2px;
    text-decoration-style: solid;
}

/* Instruction tooltip popup */
.instruction-tooltip-popup {
    position: absolute;
    background: white;
    border: 2px solid #0066cc;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: max-content;
    z-index: 10000;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: tooltipFadeIn 0.2s ease-out;
}

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

.instruction-tooltip {
    padding: 1rem;
}

.instruction-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.instruction-mnemonic {
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    font-weight: bold;
    color: #333333;
}

.instruction-category {
    background: #f0f0f0;
    color: #333333;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.instruction-syntax {
    margin: 0.5rem 0;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 4px;
    border-left: 3px solid #0066cc;
}

.instruction-syntax code {
    background: transparent;
    font-weight: bold;
}

.instruction-description {
    margin: 0.5rem 0;
    color: #333;
}

.instruction-details {
    margin: 0.5rem 0;
    font-size: 0.85rem;
    color: #666;
}

.instruction-details > div {
    margin: 0.25rem 0;
}

.instruction-examples {
    margin: 0.5rem 0;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 4px;
}

.instruction-examples pre {
    margin: 0.25rem 0 0 0;
    background: transparent;
    padding: 0;
    border: none;
    font-size: 0.8rem;
}

.instruction-notes {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: #fff3cd;
    border-left: 3px solid #ffc107;
    border-radius: 4px;
    font-size: 0.85rem;
}

.instruction-usages {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: #f0f0f0;
    border-left: 3px solid #666666;
    border-radius: 4px;
    font-size: 0.85rem;
}

.usage-link {
    color: #333333;
    text-decoration: none;
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

.usage-link:hover {
    text-decoration: underline;
}

.instruction-cross-refs {
    margin: 0.5rem 0 0 0;
    padding-top: 0.5rem;
    border-top: 1px solid #e0e0e0;
    font-size: 0.85rem;
}

.cross-ref-link {
    color: #333333;
    text-decoration: none;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    margin-right: 0.5rem;
}

.cross-ref-link:hover {
    text-decoration: underline;
}

/* Dark mode support for tooltips */
.dark-mode .instruction-tooltip-popup {
    background: #2d2d2d;
    border-color: #888888;
    color: #ffffff;
}

.dark-mode .instruction-header {
    border-bottom-color: #444;
}

.dark-mode .instruction-mnemonic {
    color: #cccccc;
}

.dark-mode .instruction-category {
    background: #404040;
    color: #cccccc;
}

.dark-mode .instruction-syntax {
    background: #363636;
    border-left-color: #888888;
}

.dark-mode .instruction-examples {
    background: #363636;
}

.dark-mode .instruction-notes {
    background: #3a3a3a;
    border-left-color: #888888;
}

.dark-mode .instruction-usages {
    background: #2a2a2a;
    border-left-color: #888888;
}

/* Assembly syntax highlighting for dark theme code blocks */
.interactive-code-block .asm-instruction,
.interactive-code-block .clickable-instruction {
    color: #82c5ff; /* Light blue for instructions */
    font-weight: 600;
}

.interactive-code-block .asm-register {
    color: #ff9d7a; /* Light orange for registers */
    font-weight: 500;
}

.interactive-code-block .asm-directive {
    color: #b794f6; /* Light purple for directives */
    font-weight: 600;
}

.interactive-code-block .asm-number {
    color: #90e59a; /* Light green for numbers */
}

.interactive-code-block .asm-comment {
    color: #a0aec0; /* Muted light gray for comments */
    font-style: italic;
}

.interactive-code-block .asm-string {
    color: #fed7aa; /* Light peach for strings */
}

/* Mobile responsive improvements for code blocks */
@media (max-width: 768px) {
    .code-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .code-actions {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .code-copy,
    .code-download {
        flex: 1;
        min-width: 120px;
        max-width: 150px;
        padding: 0.75rem;
        font-size: 0.85rem;
    }
    
    .code-language {
        text-align: center;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .code-copy,
    .code-download {
        min-width: 100px;
        padding: 0.6rem 0.5rem;
        font-size: 0.8rem;
        gap: 0.2rem;
    }
}

.dark-mode .usage-link {
    color: #cccccc;
}

.dark-mode .cross-ref-link {
    color: #cccccc;
}

.dark-mode .instruction-cross-refs {
    border-top-color: #444;
}

/* Sidebar notes and annotations */
.side-note {
    float: right;
    width: 200px;
    margin: 0 -220px 1rem 2rem;
    padding: 1rem;
    background-color: var(--highlight-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1.4;
    clear: right;
}

@media (max-width: 1200px) {
    .side-note {
        float: none;
        width: 100%;
        margin: 1rem 0;
    }
    
    /* Code block responsive adjustments */
    .code-header {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    .code-copy {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        min-width: 40px;
        min-height: 40px;
    }
    
    .interactive-code-block pre {
        padding: 1rem;
        font-size: 0.8rem;
    }
}

/* Enhanced lists */
.chapter-content ul li {
    position: relative;
    padding-left: 0.3rem;
}

.chapter-content ul li::before {
    content: "▸";
    position: absolute;
    left: -1rem;
    color: var(--accent-color);
    font-weight: bold;
}

.chapter-content ol {
    counter-reset: item;
}

.chapter-content ol li {
    display: block;
    margin-bottom: 0.3rem;
    position: relative;
    padding-left: 1.5rem;
}

.chapter-content ol li::before {
    content: counter(item, decimal) ".";
    counter-increment: item;
    position: absolute;
    left: 0;
    top: 0;
    color: var(--accent-color);
    font-weight: bold;
    width: 1.2rem;
}

/* Table styling */
.chapter-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.2rem 0;
    font-size: 0.9rem;
}

.chapter-content th,
.chapter-content td {
    padding: 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.chapter-content th {
    background-color: var(--highlight-color);
    font-weight: 600;
    color: var(--accent-color);
}

.chapter-content tr:hover {
    background-color: var(--highlight-color);
}

/* Exercise and example boxes */
.exercise-box, .example-box, .tip-box, .warning-box {
    margin: 1.2rem 0;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid;
    position: relative;
}

.exercise-box {
    background-color: #f0f0f0;
    border-left-color: #888888;
}

.example-box {
    background-color: #f8f8f8;
    border-left-color: #666666;
}

.tip-box {
    background-color: #f5f5f5;
    border-left-color: #777777;
}

.warning-box {
    background-color: #f0f0f0;
    border-left-color: #999999;
}

.exercise-box::before {
    content: "🏋️ Exercise";
    font-weight: bold;
    display: block;
    margin-bottom: 0.7rem;
    color: #333333;
}

.example-box::before {
    content: "💡 Example";
    font-weight: bold;
    display: block;
    margin-bottom: 0.7rem;
    color: #333333;
}

.tip-box::before {
    content: "💡 Tip";
    font-weight: bold;
    display: block;
    margin-bottom: 0.7rem;
    color: #333333;
}

.warning-box::before {
    content: "⚠️ Warning";
    font-weight: bold;
    display: block;
    margin-bottom: 0.7rem;
    color: #333333;
}

/* Reading tools */
.text-selection-tools {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--accent-color);
    color: var(--bg-color);
    padding: 0.5rem;
    border-radius: 8px;
    display: flex;
    gap: 0.5rem;
    z-index: 2000;
    transition: top 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.text-selection-tools.visible {
    top: 1rem;
}

.text-selection-tools button {
    background: none;
    border: none;
    color: var(--bg-color);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
}

.text-selection-tools button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Bookmark indicator */
.bookmark-indicator {
    position: absolute;
    right: -2rem;
    top: 0;
    width: 30px;
    height: 40px;
    background-color: #888888;
    clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 60%, 0 80%);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chapter-content h2:hover .bookmark-indicator,
.chapter-content h3:hover .bookmark-indicator {
    opacity: 1;
}

.bookmark-indicator.active {
    opacity: 1;
    background-color: #666666;
}

/* Reading mode enhancements */
.reading-mode {
    --nav-width: 0px;
}

.reading-mode .nav-panel {
    transform: translateX(-100%);
}

.reading-mode .main-content {
    margin-left: 0;
    max-width: 800px;
    margin: 0 auto;
    padding: 3rem 2rem;
}

.reading-mode .ai-helper,
.reading-mode .settings-panel {
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.reading-mode .ai-helper:hover,
.reading-mode .settings-panel:hover {
    opacity: 1;
}

/* Print-specific styles */
@media print {
    .chapter-content {
        font-size: 12pt;
        line-height: 1.4;
    }
    
    .chapter-content h1 {
        font-size: 24pt;
        page-break-before: always;
    }
    
    .chapter-content h2 {
        font-size: 18pt;
        page-break-after: avoid;
    }
    
    .chapter-content h3 {
        font-size: 14pt;
        page-break-after: avoid;
    }
    
    .chapter-content pre,
    .exercise-box,
    .example-box,
    .tip-box,
    .warning-box {
        page-break-inside: avoid;
    }
    
    .chapter-content a {
        color: inherit;
        text-decoration: none;
    }
    
    .chapter-content a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* Dark mode overrides */
.dark-mode {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --border-color: #404040;
    --accent-color: #ffffff;
    --highlight-color: #2a2a2a;
}

.dark-mode .exercise-box {
    background-color: #2a2a2a;
    border-left-color: #888888;
}

.dark-mode .example-box {
    background-color: #2a2a2a;
    border-left-color: #888888;
}

.dark-mode .tip-box {
    background-color: #2a2a2a;
    border-left-color: #888888;
}

.dark-mode .warning-box {
    background-color: #2a2a2a;
    border-left-color: #888888;
}

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

/* Focus management */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--accent-color);
    color: var(--bg-color);
    padding: 8px;
    text-decoration: none;
    z-index: 3000;
}

.skip-link:focus {
    top: 6px;
}

/* Custom scrollbar */
.nav-content::-webkit-scrollbar,
.ai-chat::-webkit-scrollbar {
    width: 8px;
}

.nav-content::-webkit-scrollbar-track,
.ai-chat::-webkit-scrollbar-track {
    background: var(--highlight-color);
}

.nav-content::-webkit-scrollbar-thumb,
.ai-chat::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.nav-content::-webkit-scrollbar-thumb:hover,
.ai-chat::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}