/* I Love Neurons - Main Stylesheet */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f5f5f5;
    --text-primary: #000000;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border-primary: #e5e5e5;
    --border-secondary: #f0f0f0;
    --border-tertiary: #d0d0d0;
    --sidebar-width: 240px;
    --header-height: 80px;
    --accent-color: #0066cc;
}

[data-theme="dark"] {
    --bg-primary: #151515;
    --bg-secondary: #1f1f1f;
    --bg-tertiary: #2a2a2a;
    --text-primary: #e5e5e5;
    --text-secondary: #a0a0a0;
    --text-tertiary: #808080;
    --border-primary: #333333;
    --border-secondary: #404040;
    --border-tertiary: #555555;
    --accent-color: #4d9eff;
}

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

body {
    font-family: 'Source Serif Pro', Georgia, serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    font-size: 17px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Link Styles - Applied throughout the entire document */
a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

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

a:visited {
    color: var(--accent-color);
    opacity: 0.8;
}

a:active {
    color: var(--accent-color);
    transform: translateY(1px);
}

/* External links get a subtle indicator */
a[target="_blank"]::after {
    content: ' ↗';
    font-size: 0.8em;
    opacity: 0.6;
    margin-left: 2px;
}

/* Email links styling */
a[href^="mailto:"] {
    color: var(--accent-color);
    font-weight: 500;
}

a[href^="mailto:"]:hover {
    background-color: var(--bg-secondary);
    padding: 2px 4px;
    border-radius: 3px;
    border-bottom: none;
}

/* Links in lists */
li a {
    font-weight: 500;
}

/* Links in contact section */
.contact-section a {
    font-weight: 600;
    padding: 1px 2px;
}

.contact-section a:hover {
    background-color: var(--bg-secondary);
    border-radius: 3px;
    padding: 2px 4px;
}

/* Academic/research links styling */
.section a {
    border-bottom: 1px dotted var(--accent-color);
    border-bottom-color: transparent;
}

.section a:hover {
    border-bottom-color: var(--accent-color);
    background-color: var(--bg-secondary);
    padding: 1px 3px;
    border-radius: 2px;
}

/* Strong emphasis links (like in resource lists) */
strong + a,
a strong {
    font-weight: 600;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-primary);
    padding: 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 35px 25px;
}

.sidebar-header {
    padding: 30px 20px 20px 20px;
    border-bottom: 1px solid var(--border-secondary);
}

.sidebar-title {
    font-size: 1.3em;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
    font-family: 'Source Serif Pro', serif;
}

.sidebar-subtitle {
    font-size: 0.8em;
    color: var(--text-tertiary);
    font-family: 'Source Sans Pro', sans-serif;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Floating theme toggle in upper-right like Gwern.net */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: 'Source Sans Pro', sans-serif;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 1002;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

[data-theme="dark"] .theme-toggle {
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.theme-toggle:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.header {
    text-align: center;
    margin-bottom: 50px;
    border-bottom: 1px solid var(--border-secondary);
    padding-bottom: 35px;
}

.header h1 {
    font-size: 2.2em;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 15px;
    letter-spacing: -0.01em;
    font-family: 'Source Serif Pro', serif;
}

.header .subtitle {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 1.0em;
    margin-bottom: 15px;
    line-height: 1.4;
}

.header .meta {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 0.8em;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.nav {
    padding: 20px 0 0 0;
}

.nav-btn {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 20px;
    text-decoration: none;
    letter-spacing: 0.01em;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
}

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

.nav-btn.active {
    color: var(--accent-color);
    background: var(--bg-secondary);
    border-left-color: var(--accent-color);
    font-weight: 500;
}

/* Navigation Groups for Nested Sections */
.nav-group {
    margin-bottom: 15px;
}

.nav-group-title {
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 20px;
    margin-bottom: 4px;
}

.nav-btn-child {
    padding-left: 32px; /* Additional indentation for child items */
    font-size: 13px;
    position: relative;
}

.nav-btn-child::before {
    content: '└';
    position: absolute;
    left: 20px;
    color: var(--text-tertiary);
    font-size: 12px;
}

.section {
    display: none;
}

.section.active {
    display: block;
}

.section h2 {
    font-size: 1.6em;
    font-weight: 400;
    margin: 35px 0 25px 0;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    font-family: 'Source Serif Pro', serif;
}

.section h3 {
    font-size: 1.2em;
    font-weight: 600;
    margin: 25px 0 12px 0;
    color: var(--text-primary);
    font-family: 'Source Sans Pro', sans-serif;
}

.section h4 {
    font-size: 1.0em;
    font-weight: 600;
    margin: 20px 0 8px 0;
    color: var(--text-secondary);
    font-family: 'Source Sans Pro', sans-serif;
}

.section p {
    margin-bottom: 18px;
    text-align: justify;
    hyphens: auto;
    line-height: 1.65;
}

.section ul, .section ol {
    margin-bottom: 20px;
    padding-left: 30px;
}

.section li {
    margin-bottom: 8px;
}

.dropcap {
    float: left;
    font-size: 4em;
    line-height: 0.8;
    margin: 0.1em 0.1em 0 0;
    font-weight: 400;
    color: var(--text-secondary);
}

.smallcaps {
    font-variant: small-caps;
    letter-spacing: 0.05em;
}

.sidenote {
    float: right;
    clear: right;
    margin-right: -200px;
    width: 180px;
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 0.8em;
    line-height: 1.4;
    color: var(--text-secondary);
    padding-left: 20px;
    border-left: 1px solid var(--border-primary);
}

.sidenote-number {
    font-weight: 600;
    color: var(--text-secondary);
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
}

.sidenote-ref {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8em;
    vertical-align: super;
    margin-left: 2px;
}

.collapse {
    margin: 20px 0;
}

.collapse-header {
    cursor: pointer;
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    color: var(--text-secondary);
    border-bottom: 1px dotted var(--border-tertiary);
    padding: 10px 0;
    user-select: none;
}

.collapse-header:hover {
    color: var(--text-primary);
}

.collapse-header::before {
    content: "▶ ";
    margin-right: 5px;
    transition: transform 0.2s ease;
}

.collapse-header.open::before {
    transform: rotate(90deg);
}

.collapse-content {
    display: none;
    padding: 20px 0;
    border-left: 2px solid var(--border-secondary);
    margin-left: 10px;
    padding-left: 20px;
}

.collapse-content.open {
    display: block;
}

.abstract {
    background: var(--bg-secondary);
    border-left: 4px solid var(--border-primary);
    padding: 20px;
    margin: 30px 0;
    font-style: italic;
}

.abstract::before {
    content: "Abstract: ";
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    font-style: normal;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

.epigraph {
    margin: 40px 0;
    text-align: center;
    font-style: italic;
    color: var(--text-secondary);
}

.epigraph-source {
    margin-top: 10px;
    font-size: 0.9em;
    font-variant: small-caps;
}

.bibliography {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px solid var(--border-primary);
}

.bibliography h3 {
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    margin-bottom: 20px;
}

.bibliography ul {
    list-style: none;
    padding: 0;
}

.bibliography li {
    margin-bottom: 15px;
    padding-left: 20px;
    text-indent: -20px;
}

.link-icon {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-right: 5px;
}

.neural-diagram {
    text-align: center;
    margin: 40px 0;
    padding: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
}

.highlight-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-secondary);
    padding: 20px;
    margin: 20px 0;
    border-left: 4px solid var(--border-tertiary);
}

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1a1a1a;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
}

.chat-button:hover {
    background: #333;
    transform: scale(1.1);
}

.chat-modal {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 400px;
    max-height: 600px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    z-index: 1001;
}

.chat-modal.open {
    display: flex;
}

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    font-weight: 600;
    color: #333;
    background: #f8f8f8;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-close:hover {
    color: #333;
}

.chat-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.selected-text {
    background: #f0f4f8;
    border-left: 4px solid #3498db;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    color: #555;
    border-radius: 0 4px 4px 0;
    transition: all 0.3s ease;
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.selected-text-label {
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.chat-input {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: 'Source Serif Pro', serif;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 12px;
}

.chat-input:focus {
    outline: none;
    border-color: #666;
}

.chat-send {
    background: #1a1a1a;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    letter-spacing: 0.05em;
    cursor: pointer;
    width: 100%;
    margin-bottom: 16px;
}

.chat-send:hover {
    background: #333;
}

.chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.chat-response {
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 16px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.chat-loading {
    color: #666;
    font-style: italic;
}

.chat-error {
    color: #d32f2f;
}

/* Persistent text highlighting for chat context */
.chat-context-highlight {
    background: linear-gradient(120deg, #e3f2fd 0%, #bbdefb 100%);
    padding: 1px 2px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(33, 150, 243, 0.2);
    transition: all 0.3s ease;
}

.chat-context-highlight:hover {
    background: linear-gradient(120deg, #e1f5fe 0%, #b3e5fc 100%);
    box-shadow: 0 0 0 1px rgba(33, 150, 243, 0.4);
}

/* Animation for newly highlighted text */
@keyframes highlightPulse {
    0% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.7); }
    70% { box-shadow: 0 0 0 4px rgba(33, 150, 243, 0); }
    100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}

.chat-context-highlight.newly-added {
    animation: highlightPulse 1s ease-out;
}

.chat-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.chat-clear {
    background: #f8f8f8;
    color: #666;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 4px;
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    letter-spacing: 0.05em;
    cursor: pointer;
    font-size: 14px;
    flex: 1;
}

.chat-clear:hover {
    background: #f0f0f0;
    color: #333;
}

.error-reset {
    background: #ff6b6b;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-family: 'Source Sans Pro', sans-serif;
    font-variant: small-caps;
    letter-spacing: 0.05em;
    cursor: pointer;
    font-size: 12px;
    margin-top: 10px;
    width: 100%;
}

.error-reset:hover {
    background: #ff5252;
}

/* Mobile sidebar toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 1200px) {
    .sidenote {
        float: none;
        margin-right: 0;
        width: auto;
        margin: 20px 0;
        padding: 15px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-secondary);
        border-left: 4px solid var(--border-tertiary);
    }
}

@media (max-width: 768px) {
    body {
        font-size: 16px;
    }
    
    .mobile-menu-toggle {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }
    
    .container {
        padding: 80px 15px 20px 15px;
    }

    .header h1 {
        font-size: 2em;
    }

    /* Theme toggle stays in upper-right on mobile too */
    .theme-toggle {
        top: 15px;
        right: 15px;
        font-size: 11px;
        padding: 5px 8px;
    }

    .dropcap {
        font-size: 3em;
    }

    .chat-modal {
        width: 90vw;
        max-width: 350px;
        bottom: 80px;
        right: 10px;
    }

    .chat-button {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .chat-actions {
        flex-direction: column;
        gap: 6px;
    }

    .chat-clear {
        font-size: 12px;
        padding: 6px 12px;
    }

    .chat-send {
        font-size: 14px;
    }
}
