/*
 * Mathnotes Main Styles
 * A collection of mathematics notes and interactive demonstrations
 */

/* =============================================================================
   CSS CUSTOM PROPERTIES (VARIABLES)
   ============================================================================= */

/* Light mode color scheme */
:root {
    --bg-color: #fafafa;
    --text-color: #333;
    --header-color: #333;
    --link-color: #0366d6;
    --border-color: #e1e4e8;
    --code-bg: #f6f8fa;
    --blockquote-color: #6a737d;
    --footer-color: #6a737d;
}

/* Dark mode color scheme */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0d1117;
        --text-color: #c9d1d9;
        --header-color: #f0f6fc;
        --link-color: #58a6ff;
        --border-color: #30363d;
        --code-bg: #161b22;
        --blockquote-color: #8b949e;
        --footer-color: #484f58;
    }
    
    /* Make images slightly dimmer in dark mode */
    img {
        opacity: 0.9;
    }
}

/* =============================================================================
   BASE STYLES
   ============================================================================= */

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--bg-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Responsive design - smaller width on mobile */
@media (max-width: 768px) {
    body {
        max-width: 100%;
        padding: 15px;
    }
}

header {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
    padding-bottom: 1rem;
}

header h1 {
    margin: 0;
    font-size: 2rem;
}

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

main {
    min-height: 70vh;
}

footer {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--footer-color);
    font-family: monospace;
    font-size: 0.75rem;
}

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

footer a:hover {
    text-decoration: underline;
}

/* =============================================================================
   TYPOGRAPHY
   ============================================================================= */

/* General link styling */
a {
    color: var(--link-color);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
    color: var(--header-color);
}

/* Images */
img {
    max-width: 100%;
    height: auto;
}

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

/* =============================================================================
   CODE AND PREFORMATTED TEXT
   ============================================================================= */

pre {
    background-color: var(--code-bg);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}

code {
    background-color: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 85%;
}

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

/* =============================================================================
   TABLES
   ============================================================================= */

table {
    border-collapse: collapse;
    width: 100%;
    margin: 1rem 0;
}

table th, table td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
}

table th {
    background-color: var(--code-bg);
}

/* =============================================================================
   NAVIGATION AND LISTS
   ============================================================================= */

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

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

.section-list a {
    color: var(--link-color);
    text-decoration: none;
    font-size: 1.1rem;
}

.section-list a:hover {
    text-decoration: underline;
}

.file-list {
    list-style: none;
    padding: 0;
}

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

/* =============================================================================
   INTERACTIVE DEMO COMPONENTS
   ============================================================================= */

/* Direct integration demo component */
.demo-component {
    position: relative;
    margin: 1rem 0 0.25rem 0;
    width: 100%;
}

.demo-component .demo-content {
    position: relative;
    width: 100%;
}

/* Ensure P5.js canvases in demo components are properly contained */
.demo-component canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Mobile optimization for demo components */
@media (max-width: 768px) {
    .demo-component {
        margin: 0.5rem 0;
        width: 100%;
    }
    
    .demo-component .demo-content {
        padding: 0;
        width: 100%;
    }
    
    .demo-component canvas {
        width: 100% !important;
        height: auto !important;
    }
}

/* =============================================================================
   STRUCTURED MATHEMATICAL CONTENT
   ============================================================================= */

/* Base math block styles */
.math-block {
    margin: 1.5rem 0;
    padding: 1rem;
    border-left: 3px solid var(--border-color);
    background-color: var(--code-bg);
    border-radius: 0 6px 6px 0;
}

/* Nested block styles */
.math-block-nested {
    margin: 1rem 0;
    margin-left: 0.25rem;
    padding: 0.75rem;
    padding-left: 1rem;
    border-left-width: 3px;
    background-color: rgba(0, 0, 0, 0.02);
    position: relative;
}

/* Add a subtle visual connector for nested blocks */
.math-block-nested::before {
    content: '';
    position: absolute;
    left: -3px;
    top: -1rem;
    bottom: -1rem;
    width: 3px;
    background-color: inherit;
    opacity: 0.3;
}

/* Dark mode nested blocks */
@media (prefers-color-scheme: dark) {
    .math-block-nested {
        background-color: rgba(255, 255, 255, 0.02);
    }
}

.math-block-header {
    margin-bottom: 0.75rem;
    font-weight: bold;
    color: var(--header-color);
}

.math-block-type {
    font-style: normal;
}

.math-block-title {
    margin-left: 0.5rem;
    font-weight: normal;
    font-style: normal;
}

.math-block-content {
    color: var(--text-color);
    line-height: 1.8;
}

/* Tighter spacing for nested content */
.math-block-nested .math-block-content {
    line-height: 1.7;
}

/* Remove extra spacing at the bottom of nested blocks */
.math-block-nested:last-child {
    margin-bottom: 0.5rem;
}

/* Error blocks for parsing errors */
.math-block-error {
    margin: 1.5rem 0;
    padding: 1rem;
    border: 2px solid #dc3545;
    border-left: 5px solid #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
    border-radius: 4px;
    color: #721c24;
}

.math-block-error-header {
    margin-bottom: 0.5rem;
    font-size: 1.1em;
}

.math-block-error-content {
    font-family: monospace;
    font-size: 0.9em;
    line-height: 1.4;
}

/* Dark mode error styling */
@media (prefers-color-scheme: dark) {
    .math-block-error {
        background-color: rgba(220, 53, 69, 0.15);
        color: #f8d7da;
        border-color: #dc3545;
    }
}

/* Block reference links */
.block-reference {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
    padding: 0.1em 0.2em;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.block-reference:hover {
    background-color: rgba(3, 102, 214, 0.1);
    text-decoration: underline;
}

.block-reference:active {
    background-color: rgba(3, 102, 214, 0.2);
}

/* Error styling for broken references */
.block-reference-error {
    color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
    padding: 0.1em 0.2em;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
    border: 1px dashed #dc3545;
}

/* Dark mode reference styling */
@media (prefers-color-scheme: dark) {
    .block-reference:hover {
        background-color: rgba(88, 166, 255, 0.1);
    }
    
    .block-reference:active {
        background-color: rgba(88, 166, 255, 0.2);
    }
    
    .block-reference-error {
        color: #f85149;
        background-color: rgba(248, 81, 73, 0.1);
        border-color: #f85149;
    }
}

/* Specific styles for different mathematical block types */
.math-definition {
    border-left-color: #2c5282;
    background-color: rgba(44, 82, 130, 0.05);
}

.math-theorem {
    border-left-color: #38a169;
    background-color: rgba(56, 161, 105, 0.05);
}

.math-lemma {
    border-left-color: #2b6cb0;
    background-color: rgba(43, 108, 176, 0.05);
}

.math-proposition {
    border-left-color: #3182ce;
    background-color: rgba(49, 130, 206, 0.05);
}

.math-corollary {
    border-left-color: #718096;
    background-color: rgba(113, 128, 150, 0.04);
}

.math-proof {
    border-left-color: #2d3748;
    background-color: rgba(45, 55, 72, 0.05);
    font-style: normal;
}


.math-example {
    border-left-color: #2f855a;
    background-color: rgba(47, 133, 90, 0.05);
}

.math-remark, .math-note {
    border-left-color: #4a5568;
    background-color: rgba(74, 85, 104, 0.04);
}

.math-intuition {
    border-left-color: #38b2ac;
    background-color: rgba(56, 178, 172, 0.05);
}

.math-exercise {
    border-left-color: #2c5282;
    background-color: rgba(44, 82, 130, 0.06);
}

.math-solution {
    border-left-color: #4a5568;
    background-color: rgba(74, 85, 104, 0.04);
    margin-left: 2rem;
}

/* Dark mode adjustments for structured math content */
@media (prefers-color-scheme: dark) {
    .math-definition {
        background-color: rgba(44, 82, 130, 0.12);
    }
    
    .math-theorem {
        background-color: rgba(56, 161, 105, 0.12);
    }
    
    .math-lemma {
        background-color: rgba(43, 108, 176, 0.12);
    }
    
    .math-proposition {
        background-color: rgba(49, 130, 206, 0.12);
    }
    
    .math-corollary {
        background-color: rgba(113, 128, 150, 0.1);
    }
    
    .math-proof {
        background-color: rgba(45, 55, 72, 0.12);
    }
    
    .math-example {
        background-color: rgba(47, 133, 90, 0.12);
    }
    
    .math-remark, .math-note {
        background-color: rgba(74, 85, 104, 0.1);
    }
    
    .math-intuition {
        background-color: rgba(56, 178, 172, 0.12);
    }
    
    .math-exercise {
        background-color: rgba(44, 82, 130, 0.14);
    }
    
    .math-solution {
        background-color: rgba(74, 85, 104, 0.1);
    }
}

/* Nested block color adjustments */
.math-block-nested.math-definition {
    background-color: rgba(44, 82, 130, 0.03);
}

.math-block-nested.math-theorem {
    background-color: rgba(56, 161, 105, 0.03);
}

.math-block-nested.math-lemma {
    background-color: rgba(43, 108, 176, 0.03);
}

.math-block-nested.math-proposition {
    background-color: rgba(49, 130, 206, 0.03);
}

.math-block-nested.math-corollary {
    background-color: rgba(113, 128, 150, 0.025);
}

.math-block-nested.math-proof {
    background-color: rgba(45, 55, 72, 0.03);
}

.math-block-nested.math-example {
    background-color: rgba(47, 133, 90, 0.03);
}

/* Dark mode nested blocks */
@media (prefers-color-scheme: dark) {
    .math-block-nested.math-definition {
        background-color: rgba(44, 82, 130, 0.06);
    }
    
    .math-block-nested.math-theorem {
        background-color: rgba(56, 161, 105, 0.06);
    }
    
    .math-block-nested.math-lemma {
        background-color: rgba(43, 108, 176, 0.06);
    }
    
    .math-block-nested.math-proposition {
        background-color: rgba(49, 130, 206, 0.06);
    }
    
    .math-block-nested.math-corollary {
        background-color: rgba(113, 128, 150, 0.05);
    }
    
    .math-block-nested.math-proof {
        background-color: rgba(45, 55, 72, 0.06);
    }
    
    .math-block-nested.math-example {
        background-color: rgba(47, 133, 90, 0.06);
    }
}

/* =============================================================================
   EMBEDDED BLOCKS (TRANSCLUSION)
   ============================================================================= */

/* Container for embedded/transcluded blocks */
.embedded-block {
    margin: 1.5rem 0;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--border-color);
    background-color: var(--code-bg);
    border-radius: 6px;
    position: relative;
}

/* Header for embedded blocks */
.embedded-header {
    margin-bottom: 0.75rem;
    font-weight: bold;
    color: var(--header-color);
    font-size: 0.95em;
    opacity: 0.9;
}

/* Content of embedded blocks */
.embedded-content {
    color: var(--text-color);
    line-height: 1.8;
}

/* Source attribution for embedded blocks */
.embedded-source {
    margin-top: 0.75rem;
    font-size: 0.85em;
    color: var(--footer-color);
    text-align: right;
}

.embedded-source a {
    color: var(--link-color);
    text-decoration: none;
}

.embedded-source a:hover {
    text-decoration: underline;
}

/* Type-specific embedded block colors - matching the original block colors */
.embedded-block.embedded-definition {
    border-left-color: #2c5282;
    background-color: rgba(44, 82, 130, 0.05);
}

.embedded-block.embedded-theorem {
    border-left-color: #2d3748;
    background-color: rgba(45, 55, 72, 0.05);
}

.embedded-block.embedded-lemma {
    border-left-color: #2b6cb0;
    background-color: rgba(43, 108, 176, 0.05);
}

.embedded-block.embedded-proposition {
    border-left-color: #3182ce;
    background-color: rgba(49, 130, 206, 0.05);
}

.embedded-block.embedded-corollary {
    border-left-color: #718096;
    background-color: rgba(113, 128, 150, 0.04);
}

.embedded-block.embedded-proof {
    border-left-color: #38a169;
    background-color: rgba(56, 161, 105, 0.05);
}

.embedded-block.embedded-example {
    border-left-color: #2f855a;
    background-color: rgba(47, 133, 90, 0.05);
}

/* Dark mode embedded blocks */
@media (prefers-color-scheme: dark) {
    .embedded-block {
        background-color: rgba(255, 255, 255, 0.03);
        border-color: var(--border-color);
    }
    
    .embedded-block.embedded-definition {
        background-color: rgba(44, 82, 130, 0.12);
    }
    
    .embedded-block.embedded-theorem {
        background-color: rgba(45, 55, 72, 0.12);
    }
    
    .embedded-block.embedded-lemma {
        background-color: rgba(43, 108, 176, 0.12);
    }
    
    .embedded-block.embedded-proposition {
        background-color: rgba(49, 130, 206, 0.12);
    }
    
    .embedded-block.embedded-corollary {
        background-color: rgba(113, 128, 150, 0.1);
    }
    
    .embedded-block.embedded-proof {
        background-color: rgba(56, 161, 105, 0.12);
    }
    
    .embedded-block.embedded-example {
        background-color: rgba(47, 133, 90, 0.12);
    }
}

/* Error styling for failed embeds */
.embed-error {
    color: #dc3545;
    font-weight: bold;
    background-color: rgba(220, 53, 69, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
}

@media (prefers-color-scheme: dark) {
    .embed-error {
        background-color: rgba(220, 53, 69, 0.2);
        color: #f8d7da;
    }
}

/* Math content toggle button styles */
.math-content-toggle-container {
    position: sticky;
    top: 10px;
    z-index: 100;
    display: flex;
    justify-content: flex-end;
    margin: 1rem 0;
    padding: 0 1rem;
}

.math-content-toggle {
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.math-content-toggle:hover {
    background-color: var(--link-color);
    color: var(--bg-color);
    border-color: var(--link-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.math-content-toggle:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Dark mode toggle button */
@media (prefers-color-scheme: dark) {
    .math-content-toggle {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    }
    
    .math-content-toggle:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    }
}

/* =============================================================================
   MATHJAX MOBILE OPTIMIZATION
   ============================================================================= */

/* Fix MathJax font sizing on mobile devices */
@media (max-width: 768px) {
    /* Scale up MathJax content on mobile */
    mjx-container {
        font-size: 120% !important;
    }
    
    /* Ensure inline math matches surrounding text */
    mjx-container[display="false"] {
        font-size: inherit !important;
        vertical-align: baseline;
    }
    
    /* Handle overflow for wide equations */
    mjx-container[display="true"] {
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Add padding to scrollable equations */
    mjx-container[display="true"] mjx-math {
        padding: 0.5em 0;
    }
    
    /* Ensure MathJax doesn't get too small */
    .mjx-chtml {
        min-font-size: 16px !important;
    }
    
    /* Fix alignment issues */
    mjx-container {
        vertical-align: middle !important;
    }
}