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

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --warning: #d29922;
    --success: #3fb950;
    --code-bg: #161b22;
    --sidebar-width: 280px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.sidebar-header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.sidebar-header .subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

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

/* Category styles */
.nav-category {
    margin-bottom: 4px;
}

.category-header {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s;
    user-select: none;
}

.category-header:hover {
    background-color: var(--bg-tertiary);
}

.category-icon {
    font-size: 1.1em;
    margin-right: 10px;
}

.category-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.category-toggle {
    font-size: 0.7em;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.category-header.collapsed .category-toggle {
    transform: rotate(-90deg);
}

/* Topic list styles */
.nav-topics {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    opacity: 1;
}

.nav-topics.collapsed {
    max-height: 0;
    opacity: 0;
}

.nav-topics li {
    margin: 0;
}

.nav-link {
    display: block;
    padding: 8px 20px 8px 50px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.nav-link.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background-color: rgba(88, 166, 255, 0.1);
    font-weight: 500;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main content */
.content {
    margin-left: var(--sidebar-width);
    padding: 40px 60px;
    max-width: 900px;
}

.section {
    padding-bottom: 60px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 60px;
}

.section:last-child {
    border-bottom: none;
}

/* Typography */
h2 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 30px 0 15px;
    color: var(--text-primary);
}

h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 10px;
    color: var(--text-primary);
}

p {
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.lead {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 25px;
}

/* Lists */
ul, ol {
    margin: 0 0 20px 20px;
    color: var(--text-secondary);
}

li {
    margin-bottom: 8px;
}

li strong {
    color: var(--text-primary);
}

ul.references {
    list-style: none;
    margin-left: 0;
}

ul.references li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

ul.references li:last-child {
    border-bottom: none;
}

ul.references em {
    color: var(--text-muted);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.9rem;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border: 1px solid var(--border-color);
}

th {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

td {
    color: var(--text-secondary);
}

tr:hover td {
    background-color: var(--bg-secondary);
}

/* Code */
pre {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin: 20px 0;
}

code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
}

p code, li code {
    background-color: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* Cards */
.card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 20px;
    margin: 20px 0;
}

.card h3, .card h4 {
    margin-top: 0;
}

.card p:last-child,
.card ul:last-child,
.card ol:last-child {
    margin-bottom: 0;
}

.card.highlight {
    border-left: 3px solid var(--accent);
}

.card.warning {
    border-left: 3px solid var(--warning);
}

.card.warning h4 {
    color: var(--warning);
}

/* Responsive */
@media (max-width: 1100px) {
    .content {
        padding: 30px 40px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: relative;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: none;
        margin-bottom: 0;
    }
    
    .nav-list {
        display: none;
    }
    
    .sidebar-footer {
        display: none;
    }
    
    .content {
        margin-left: 0;
        padding: 30px 20px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Selection */
::selection {
    background-color: var(--accent);
    color: var(--bg-primary);
}

/* Breadcrumb navigation */
.breadcrumb {
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumb ol {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.breadcrumb li {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.breadcrumb li:not(:last-child)::after {
    content: "›";
    margin-left: 8px;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

.breadcrumb a:hover {
    color: var(--text-primary);
}

.breadcrumb .current {
    color: var(--text-primary);
    font-weight: 500;
}

/* Topic page */
.topic-page {
    max-width: 900px;
}

.topic-header {
    margin-bottom: 40px;
}

.topic-header h1 {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.topic-description {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 0;
}

.topic-content {
    margin-bottom: 60px;
}

/* Related topics */
.related-topics {
    margin-top: 60px;
    padding-top: 30px;
    border-top: 2px solid var(--border-color);
}

.related-topics h3 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.related-topics ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.related-topics li {
    margin: 0;
}

.related-topics a {
    display: flex;
    flex-direction: column;
    padding: 15px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s;
}

.related-topics a:hover {
    border-color: var(--accent);
    background-color: var(--bg-tertiary);
}

.related-category {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 5px;
}

.related-title {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* Home page category cards */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-top: 40px;
}

.category-card {
    padding: 30px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s;
}

.category-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.category-card-icon {
    font-size: 2.5em;
    margin-bottom: 15px;
}

.category-card h2 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    border-bottom: none;
    padding-bottom: 0;
}

.category-card p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.category-card-topics {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-card-topics li {
    margin-bottom: 8px;
}

.category-card-topics a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.category-card-topics a:hover {
    color: var(--text-primary);
}

/* Print styles */
@media print {
    .sidebar {
        display: none;
    }
    
    .content {
        margin-left: 0;
        max-width: 100%;
    }
    
    .section {
        page-break-inside: avoid;
    }
}

/* Math equations (MathJax) */
.MathJax {
    color: var(--text-primary) !important;
}

mjx-container {
    overflow-x: auto;
    overflow-y: hidden;
}

mjx-container[display="true"] {
    display: block;
    text-align: center;
    margin: 1.5em 0;
}

/* Inline math */
mjx-container[display="false"] {
    display: inline-block;
    margin: 0 0.2em;
}

/* Display math in paragraphs */
p > mjx-container[display="true"] {
    margin: 1em 0;
}
