/* Megadox Book Reader Styles - Mobile-First Responsive Design */

:root {
    --serif: "Palatino", "Palatino Linotype", "Hoefler Text", Georgia, serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --mono: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --primary: #2c3e50;
    --secondary: #34495e;
    --accent: #3498db;
    --light-bg: #f8f9fa;
    --border: #dee2e6;
    --code-bg: #f4f4f4;
    --sidebar-width: 280px;
}

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

body {
    font-family: var(--serif);
    line-height: 1.7;
    color: var(--primary);
    background: #fff;
    font-size: 18px;
}

/* Mobile-first layout */
.book-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Sidebar/TOC */
.toc-sidebar {
    background: var(--light-bg);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    max-height: 100vh;
    overflow-y: auto;
}

.toc-toggle {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-family: var(--sans);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1rem;
}

.toc-toggle:hover {
    background: #2980b9;
}

.toc-content {
    display: none;
}

.toc-content.active {
    display: block;
}

.toc-title {
    font-family: var(--sans);
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--primary);
}

#TOC {
    font-family: var(--sans);
    font-size: 0.9rem;
}

#TOC ul {
    list-style: none;
    padding-left: 0;
}

#TOC > ul > li {
    margin-bottom: 0.75rem;
}

/* Native details/summary TOC styling */
#TOC details {
    margin: 0.5rem 0;
}

#TOC summary {
    cursor: pointer;
    user-select: none;
    list-style: none; /* Remove default marker */
    padding: 0.25rem 0;
    display: flex;
    align-items: center;
    transition: color 0.2s ease;
}

/* Hide default disclosure triangle */
#TOC summary::-webkit-details-marker {
    display: none;
}

#TOC summary::before {
    content: '▶';
    display: inline-block;
    width: 1em;
    margin-right: 0.5rem;
    color: var(--accent);
    font-size: 0.75em;
    transition: transform 0.2s ease;
}

#TOC details[open] > summary::before {
    transform: rotate(90deg);
}

#TOC summary:hover {
    color: var(--accent);
}

#TOC .toc-nested {
    padding-left: 1.25rem;
    margin-top: 0.5rem;
    border-left: 2px solid rgba(52, 152, 219, 0.15);
    margin-left: 0.5rem;
}

#TOC details details .toc-nested {
    border-left-color: rgba(52, 152, 219, 0.1);
}

#TOC li {
    margin-bottom: 0.5rem;
    line-height: 1.4;
    position: relative;
}

#TOC li.toc-details-item {
    list-style: none;
}

#TOC > ul > li > a {
    font-weight: 600;
    font-size: 0.95rem;
}

#TOC ul ul li a {
    font-size: 0.875rem;
    opacity: 0.9;
}

#TOC ul ul ul li a {
    font-size: 0.85rem;
    opacity: 0.85;
}

#TOC a {
    color: var(--primary);
    text-decoration: none;
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

#TOC a:hover {
    background: rgba(52, 152, 219, 0.1);
    color: var(--accent);
}

/* Expand/collapse all button */
.toc-controls {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
}

.toc-control-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: white;
    color: var(--primary);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--sans);
    transition: all 0.2s ease;
}

.toc-control-btn:hover {
    background: var(--light-bg);
    border-color: var(--accent);
}

/* Search container */
.search-container {
    margin-bottom: 1.5rem;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-family: var(--sans);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
    text-decoration: none;
    transition: background 0.2s ease;
}

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

.search-result-item:hover {
    background: var(--light-bg);
}

.search-result-icon {
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.search-result-title {
    flex: 1;
    font-size: 0.875rem;
    line-height: 1.4;
}

.search-result-title mark {
    background: #ffd700;
    padding: 0.1em 0.2em;
    border-radius: 2px;
    font-weight: 600;
}

.search-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--secondary);
    font-style: italic;
    font-size: 0.875rem;
}

/* Main content */
.book-content {
    flex: 1;
    padding: 2rem 1.5rem;
    max-width: 100%;
}

.book-header {
    text-align: center;
    padding-bottom: 2rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
}

.book-title {
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.book-subtitle {
    font-size: 1.25rem;
    color: var(--secondary);
    font-weight: 400;
}

.ai-notice {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 1rem;
    margin: 2rem 0;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

h1 {
    font-size: 2rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

h2 {
    font-size: 1.75rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}

h3 {
    font-size: 1.5rem;
}

h4 {
    font-size: 1.25rem;
}

p {
    margin-bottom: 1rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Code blocks */
code {
    font-family: var(--mono);
    font-size: 0.875em;
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    line-height: 1.4;
}

pre code {
    background: none;
    padding: 0;
    font-size: 0.875rem;
}

/* Lists */
ul, ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
    list-style-position: outside;
}

ul {
    list-style-type: disc;
}

ol {
    list-style-type: decimal;
}

li {
    margin-bottom: 0.5rem;
    display: list-item;
}

/* Nested lists */
ul ul {
    list-style-type: circle;
    margin-top: 0.5rem;
}

ul ul ul {
    list-style-type: square;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    overflow-x: auto;
    display: block;
}

@media (min-width: 768px) {
    table {
        display: table;
    }
}

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

th {
    background: var(--light-bg);
    font-weight: 600;
    font-family: var(--sans);
}

/* Blockquotes */
blockquote {
    border-left: 4px solid var(--accent);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--secondary);
    font-style: italic;
}

/* Horizontal rules */
hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 2rem 0;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
}

/* Desktop layout */
@media (min-width: 1024px) {
    .book-container {
        flex-direction: row;
    }

    .toc-sidebar {
        width: var(--sidebar-width);
        border-bottom: none;
        border-right: 1px solid var(--border);
        position: sticky;
        top: 0;
        height: 100vh;
    }

    .toc-toggle {
        display: none;
    }

    .toc-content {
        display: block !important;
    }

    .book-content {
        padding: 3rem 4rem;
        max-width: 900px;
        margin: 0 auto;
    }

    .book-title {
        font-size: 2.5rem;
    }

    h1 {
        font-size: 2.25rem;
    }

    h2 {
        font-size: 1.875rem;
    }
}

/* Print styles */
@media print {
    .toc-sidebar {
        display: none;
    }

    .book-content {
        max-width: 100%;
        padding: 0;
    }

    a {
        color: var(--primary);
        text-decoration: none;
    }

    pre, code {
        background: #f8f8f8;
    }
}

/* Syntax highlighting - GitHub-inspired professional theme */
.sourceCode {
    overflow-x: auto;
}

code > span.kw { color: #d73a49; font-weight: 600; } /* Keywords - red */
code > span.dt { color: #6f42c1; font-weight: 600; } /* Data types - purple */
code > span.dv { color: #005cc5; } /* Decimal values - blue */
code > span.bn { color: #005cc5; } /* Base-N integers - blue */
code > span.fl { color: #005cc5; } /* Floats - blue */
code > span.ch { color: #032f62; } /* Chars - dark blue */
code > span.st { color: #032f62; } /* Strings - dark blue */
code > span.co { color: #6a737d; font-style: italic; } /* Comments - gray */
code > span.ot { color: #005cc5; } /* Other tokens - blue */
code > span.al { color: #e36209; font-weight: bold; } /* Alerts - orange */
code > span.fu { color: #6f42c1; } /* Functions - purple */
code > span.er { color: #b31d28; font-weight: bold; background: #ffeef0; } /* Errors */
code > span.wa { color: #e36209; font-weight: bold; } /* Warnings - orange */
code > span.cn { color: #005cc5; } /* Constants - blue */
code > span.sc { color: #032f62; } /* Special chars - dark blue */
code > span.vs { color: #032f62; } /* Verbatim strings - dark blue */
code > span.ss { color: #22863a; } /* Special strings - green */
code > span.im { color: #d73a49; } /* Imports - red */
code > span.va { color: #e36209; } /* Variables - orange */
code > span.cf { color: #d73a49; font-weight: 600; } /* Control flow - red */
code > span.op { color: #d73a49; } /* Operators - red */
code > span.bu { color: #005cc5; } /* Built-ins - blue */
code > span.ex { color: #22863a; } /* Extensions/commands - green */
code > span.pp { color: #d73a49; } /* Preprocessor - red */
code > span.at { color: #005cc5; } /* Attributes - blue */
code > span.do { color: #6a737d; font-style: italic; } /* Documentation - gray */
code > span.an { color: #6a737d; font-style: italic; } /* Annotations - gray */
code > span.cv { color: #6a737d; font-style: italic; } /* Comments (verbose) - gray */
code > span.in { color: #005cc5; font-style: italic; } /* Information - blue */

/* Code block line numbers */
.sourceCode a {
    color: inherit;
    text-decoration: none;
}

.sourceCode a:hover {
    text-decoration: none;
    background: transparent;
}
