/* MLB Analytics Textbook - Professional Stylesheet */
/* Font: Raleway | Code: Fira Code */

:root {
    /* Premium color palette */
    --mlb-blue: #002D72;
    --mlb-red: #D50032;
    --mlb-navy: #041E42;
    --mlb-white: #FFFFFF;

    /* Extended palette */
    --accent-gold: #C9A227;
    --accent-teal: #0077B6;
    --surface-light: #F7F9FC;
    --surface-dark: #0D1117;

    /* Functional colors */
    --primary: var(--mlb-blue);
    --secondary: #64748B;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: var(--mlb-red);
    --info: #3B82F6;

    /* Code colors */
    --code-bg: #1a1b26;
    --code-text: #c0caf5;
    --code-r: #2D6EB5;
    --code-python: #FFD43B;

    /* Layout */
    --sidebar-width: 300px;
    --header-height: 70px;
    --content-max-width: 860px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;

    /* Typography */
    --font-sans: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-glow: 0 0 40px rgba(0, 45, 114, 0.15);

    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Variables */
[data-bs-theme="dark"] {
    --bs-body-bg: #0D1117;
    --bs-body-color: #E6EDF3;
    --bs-card-bg: #161B22;
    --bs-border-color: #30363D;
    --bs-secondary-color: #A8B2C1;
    --bs-tertiary-color: #8B949E;
    --surface-light: #161B22;

    /* Override Bootstrap muted colors for dark mode */
    --bs-secondary-rgb: 168, 178, 193;
    --text-muted: #A8B2C1;
    --text-secondary: #C9D1D9;
}

/* Dark mode text-muted override - higher contrast */
[data-bs-theme="dark"] .text-muted {
    color: #A8B2C1 !important;
}

[data-bs-theme="dark"] .text-secondary {
    color: #C9D1D9 !important;
}

/* ==================== Base Styles ==================== */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.75;
    color: #1E293B;
    background-color: var(--surface-light);
    letter-spacing: -0.01em;
}

[data-bs-theme="dark"] body {
    background-color: var(--surface-dark);
    color: #E6EDF3;
}

::selection {
    background: var(--mlb-blue);
    color: white;
}

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

a:hover {
    color: var(--mlb-navy);
}

[data-bs-theme="dark"] a {
    color: #58A6FF;
}

[data-bs-theme="dark"] a:hover {
    color: #79B8FF;
}

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

/* ==================== Typography ==================== */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-sans);
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 1rem;
    color: var(--mlb-navy);
    letter-spacing: -0.02em;
}

[data-bs-theme="dark"] h1,
[data-bs-theme="dark"] h2,
[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] h4,
[data-bs-theme="dark"] h5,
[data-bs-theme="dark"] h6 {
    color: #F0F6FC;
}

h1 {
    font-size: 2.75rem;
    font-weight: 800;
}

h2 {
    font-size: 1.875rem;
    margin-top: 3rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #E2E8F0;
    position: relative;
}

h2::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, var(--mlb-blue), var(--mlb-red));
}

[data-bs-theme="dark"] h2 {
    border-color: #30363D;
}

h3 {
    font-size: 1.375rem;
    font-weight: 600;
}

h4 {
    font-size: 1.125rem;
    font-weight: 600;
}

p {
    margin-bottom: 1.25rem;
}

/* Lead text */
.lead {
    font-size: 1.25rem;
    font-weight: 400;
    line-height: 1.6;
    color: #475569;
}

[data-bs-theme="dark"] .lead {
    color: #C9D1D9;
}

/* ==================== Code Styling ==================== */

code,
pre,
code[class*="language-"],
pre[class*="language-"],
.token {
    font-family: var(--font-mono) !important;
}

code {
    font-size: 0.875em;
    font-weight: 500;
    background: linear-gradient(135deg, rgba(0, 45, 114, 0.08), rgba(0, 45, 114, 0.04));
    color: var(--mlb-navy);
    padding: 0.2em 0.5em;
    border-radius: 6px;
    border: 1px solid rgba(0, 45, 114, 0.1);
}

[data-bs-theme="dark"] code {
    background: linear-gradient(135deg, rgba(99, 179, 237, 0.15), rgba(99, 179, 237, 0.08));
    color: #7DD3FC;
    border-color: rgba(99, 179, 237, 0.2);
}

/* ==================== Navbar ==================== */

#mainNav {
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-blue) 50%, var(--mlb-navy) 100%);
    box-shadow: var(--shadow-lg);
    height: var(--header-height);
    z-index: 1030;
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-icon {
    font-size: 1.75rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.navbar-brand:hover {
    opacity: 0.9;
}

.nav-link {
    font-weight: 500;
    font-size: 0.9375rem;
    padding: 0.5rem 1rem !important;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.navbar .dropdown-menu {
    max-height: 70vh;
    overflow-y: auto;
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    padding: 0.5rem;
    background: #1E293B;
}

.navbar .dropdown-item {
    border-radius: var(--border-radius-sm);
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    color: rgba(255, 255, 255, 0.85);
}

.navbar .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
}

.navbar .dropdown-item:focus {
    background: rgba(88, 166, 255, 0.2);
    color: #FFFFFF;
    outline: none;
}

.chapter-num {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8em;
    font-weight: 600;
    margin-right: 0.375rem;
}

/* Search */
#searchForm {
    position: relative;
}

#globalSearch {
    width: 220px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
    color: white;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    transition: all var(--transition-normal);
}

#globalSearch::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#globalSearch:focus {
    width: 300px;
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
    outline: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 420px;
    max-height: 450px;
    overflow-y: auto;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    z-index: 1050;
    display: none;
    border: 1px solid #E2E8F0;
}

[data-bs-theme="dark"] .search-results {
    background: #161B22;
    border-color: #30363D;
}

.search-results.show {
    display: block;
    animation: slideDown 0.2s ease;
}

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

.search-result-item {
    display: block;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #E2E8F0;
    color: #1E293B;
    transition: all var(--transition-fast);
}

[data-bs-theme="dark"] .search-result-item {
    color: #E6EDF3;
    border-color: #30363D;
}

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

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

[data-bs-theme="dark"] .search-result-item:hover {
    background: #21262D;
}

/* Dark Mode Toggle */
#darkModeToggle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

#darkModeToggle:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
    transform: rotate(15deg);
}

/* ==================== Reading Progress ==================== */

.reading-progress {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.05);
    z-index: 1029;
}

[data-bs-theme="dark"] .reading-progress {
    background: rgba(255, 255, 255, 0.05);
}

.reading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--mlb-blue), var(--accent-teal), var(--mlb-red));
    width: 0;
    transition: width 0.1s linear;
    box-shadow: 0 0 10px rgba(0, 45, 114, 0.5);
}

/* ==================== Sidebar ==================== */

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: white;
    border-right: 1px solid #E2E8F0;
    overflow-y: auto;
    z-index: 1020;
    transition: transform var(--transition-normal);
}

[data-bs-theme="dark"] .sidebar {
    background: #0D1117;
    border-color: #21262D;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #E2E8F0;
    background: linear-gradient(180deg, var(--surface-light) 0%, white 100%);
}

[data-bs-theme="dark"] .sidebar-header {
    background: linear-gradient(180deg, #161B22 0%, #0D1117 100%);
    border-color: #21262D;
}

.sidebar-header h5 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--secondary);
    margin: 0;
    font-weight: 600;
}

.sidebar-nav {
    list-style: none;
    padding: 0.75rem 0;
    margin: 0;
}

.sidebar-nav .nav-item {
    margin: 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: #475569;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
    font-weight: 500;
    font-size: 0.9375rem;
}

[data-bs-theme="dark"] .sidebar-nav .nav-link {
    color: #B0BAC5;
}

.sidebar-nav .nav-link:hover {
    background: var(--surface-light);
    color: var(--primary);
    border-left-color: var(--primary);
}

[data-bs-theme="dark"] .sidebar-nav .nav-link:hover {
    background: #161B22;
    color: #58A6FF;
}

.sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, rgba(0, 45, 114, 0.1), transparent);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

[data-bs-theme="dark"] .sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, rgba(88, 166, 255, 0.15), transparent);
    color: #58A6FF;
    border-left-color: #58A6FF;
}

.sidebar-nav .chapter-number {
    min-width: 2rem;
    font-weight: 700;
    color: var(--primary);
    font-size: 0.875rem;
}

[data-bs-theme="dark"] .sidebar-nav .chapter-number {
    color: #58A6FF;
}

.sidebar-nav .nav-link.active .chapter-number {
    color: var(--primary);
}

.sidebar-nav .chapter-title {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Section sub-nav */
.section-nav {
    list-style: none;
    padding: 0.5rem 0;
    margin: 0;
    background: var(--surface-light);
}

[data-bs-theme="dark"] .section-nav {
    background: #161B22;
}

.section-nav li a {
    display: block;
    padding: 0.5rem 1.5rem 0.5rem 3.5rem;
    font-size: 0.85rem;
    color: #64748B;
    border-left: 3px solid transparent;
    transition: all var(--transition-fast);
}

[data-bs-theme="dark"] .section-nav li a {
    color: #A8B2C1;
}

[data-bs-theme="dark"] .section-nav li a:hover {
    color: #58A6FF;
    border-left-color: #58A6FF;
    background: rgba(88, 166, 255, 0.08);
}

.section-nav li a:hover {
    color: var(--primary);
    border-left-color: var(--primary);
    background: rgba(0, 45, 114, 0.05);
}

.section-nav .section-number {
    color: var(--primary);
    margin-right: 0.5rem;
    font-weight: 600;
    font-size: 0.8rem;
}

.sidebar-footer {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #E2E8F0;
    background: var(--surface-light);
}

[data-bs-theme="dark"] .sidebar-footer {
    background: #161B22;
    border-color: #21262D;
}

/* Sidebar Toggle (Mobile) */
.sidebar-toggle {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 1025;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: none;
    box-shadow: var(--shadow-xl);
    background: var(--mlb-blue);
    border: none;
    color: white;
}

.sidebar-toggle:hover {
    background: var(--mlb-navy);
    transform: scale(1.05);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1019;
    display: none;
}

.sidebar-backdrop.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== Main Content ==================== */

.chapter-content-wrapper {
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height));
    background: white;
}

[data-bs-theme="dark"] .chapter-content-wrapper {
    background: #0D1117;
}

.chapter-content {
    max-width: var(--content-max-width);
}

/* Chapter Header */
.chapter-header {
    padding: 3rem 0;
    border-bottom: 1px solid #E2E8F0;
    margin-bottom: 2rem;
}

[data-bs-theme="dark"] .chapter-header {
    border-color: #21262D;
}

.chapter-number-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--mlb-blue);
    display: inline-block;
    padding: 0.375rem 0.875rem;
    background: linear-gradient(135deg, rgba(0, 45, 114, 0.1), rgba(0, 45, 114, 0.05));
    border-radius: 50px;
    margin-bottom: 1rem;
}

[data-bs-theme="dark"] .chapter-number-label {
    background: rgba(88, 166, 255, 0.15);
    color: #58A6FF;
}

.chapter-meta .badge {
    font-weight: 600;
    padding: 0.5rem 0.875rem;
    border-radius: 50px;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
}

/* Section Titles */
.section-title {
    position: relative;
    margin-top: 3rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-number {
    color: var(--primary);
    font-weight: 800;
    margin-right: 0.25rem;
}

.section-anchor {
    color: #CBD5E1;
    text-decoration: none;
    margin-left: 0.5rem;
    opacity: 0;
    transition: all var(--transition-fast);
    font-size: 0.875em;
}

.section-title:hover .section-anchor {
    opacity: 1;
}

.section-anchor:hover {
    color: var(--primary);
}

/* Table of Contents */
.toc-card {
    border: none;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    background: white;
}

[data-bs-theme="dark"] .toc-card {
    background: #161B22;
}

.toc-card .card-header {
    background: linear-gradient(135deg, var(--surface-light), white);
    border-bottom: 1px solid #E2E8F0;
    padding: 1rem 1.25rem;
}

[data-bs-theme="dark"] .toc-card .card-header {
    background: linear-gradient(135deg, #21262D, #161B22);
    border-color: #30363D;
}

.toc-list {
    columns: 2;
    column-gap: 2rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.toc-item {
    break-inside: avoid;
    margin-bottom: 0.375rem;
}

.toc-item.toc-sub {
    margin-left: 1.5rem;
    font-size: 0.9rem;
}

.toc-list a {
    color: #475569;
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

[data-bs-theme="dark"] .toc-list a {
    color: #B0BAC5;
}

.toc-list a:hover {
    color: var(--primary);
    background: var(--surface-light);
}

[data-bs-theme="dark"] .toc-list a:hover {
    background: #21262D;
    color: #58A6FF;
}

.toc-number {
    font-weight: 700;
    color: var(--primary);
    margin-right: 0.5rem;
}

/* Page TOC (right sidebar) */
.page-toc-wrapper {
    position: sticky;
    top: calc(var(--header-height) + 2rem);
    height: fit-content;
}

.page-toc {
    padding: 1rem 0;
    border-left: 2px solid #E2E8F0;
}

[data-bs-theme="dark"] .page-toc {
    border-color: #30363D;
}

.page-toc-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--secondary);
    font-weight: 700;
    padding-left: 1rem;
    margin-bottom: 0.75rem;
}

.page-toc a {
    display: block;
    font-size: 0.8125rem;
    color: #64748B;
    padding: 0.375rem 1rem;
    margin-left: -2px;
    border-left: 2px solid transparent;
    transition: all var(--transition-fast);
}

[data-bs-theme="dark"] .page-toc a {
    color: #A8B2C1;
}

.page-toc a:hover,
.page-toc a.active {
    color: var(--primary);
    border-left-color: var(--primary);
}

[data-bs-theme="dark"] .page-toc a:hover,
[data-bs-theme="dark"] .page-toc a.active {
    color: #58A6FF;
    border-left-color: #58A6FF;
}

/* ==================== Code Blocks ==================== */

.code-examples-container {
    margin: 2rem 0;
}

.code-block-wrapper {
    margin: 1.5rem 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid #374151;
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #1f2937;
    border-bottom: 1px solid #374151;
}

.code-block-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.code-language-badge {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: #374151;
    color: #e5e7eb;
}

.code-language-badge i {
    margin-right: 0.25rem;
}

.code-title {
    font-size: 0.875rem;
    color: #9ca3af;
    font-weight: 400;
}

.btn-copy {
    background: #374151;
    border: none;
    color: #e5e7eb;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.375rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-copy:hover {
    background: #4b5563;
    color: #fff;
}

.btn-copy.copied {
    background: #059669;
    color: #fff;
}

/* Code Block - Main Styling */
pre[class*="language-"] {
    margin: 0 !important;
    padding: 1.25rem !important;
    background: #0d1117 !important;
    border-radius: 0 !important;
    font-size: 0.875rem !important;
    line-height: 1.6 !important;
    max-height: 500px;
    overflow: auto;
}

pre[class*="language-"] code,
code[class*="language-"] {
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace !important;
    font-size: 0.875rem !important;
    color: #e6edf3 !important;
    background: transparent !important;
    text-shadow: none !important;
    border: none !important;
    padding: 0 !important;
}

/* Line Numbers */
.line-numbers .line-numbers-rows {
    border-right: 1px solid #30363d !important;
    padding-right: 0.75rem;
}

.line-numbers-rows > span:before {
    color: #6e7681 !important;
}

/* ==================== Syntax Highlighting (GitHub Dark Theme) ==================== */

/* Comments */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #8b949e !important;
    font-style: italic;
}

/* Punctuation */
.token.punctuation {
    color: #e6edf3 !important;
}

/* Strings */
.token.string,
.token.char,
.token.attr-value {
    color: #a5d6ff !important;
}

/* Numbers & Constants */
.token.number,
.token.boolean,
.token.constant {
    color: #79c0ff !important;
}

/* Keywords */
.token.keyword,
.token.atrule {
    color: #ff7b72 !important;
}

/* Functions */
.token.function {
    color: #d2a8ff !important;
}

/* Classes & Types */
.token.class-name,
.token.builtin {
    color: #ffa657 !important;
}

/* Variables & Parameters */
.token.variable,
.token.parameter {
    color: #ffa657 !important;
}

/* Operators */
.token.operator {
    color: #ff7b72 !important;
}

/* Properties & Attributes */
.token.property,
.token.attr-name {
    color: #79c0ff !important;
}

/* Tags (HTML/XML) */
.token.tag {
    color: #7ee787 !important;
}

/* Selectors (CSS) */
.token.selector {
    color: #7ee787 !important;
}

/* Regex */
.token.regex {
    color: #a5d6ff !important;
}

/* Important & Bold */
.token.important,
.token.bold {
    font-weight: bold;
}

/* Italic */
.token.italic {
    font-style: italic;
}

/* Inserted (diff) */
.token.inserted {
    color: #7ee787 !important;
    background: rgba(46, 160, 67, 0.15) !important;
}

/* Deleted (diff) */
.token.deleted {
    color: #ffa198 !important;
    background: rgba(248, 81, 73, 0.15) !important;
}

/* Code Explanation Box */
.code-explanation {
    padding: 0.875rem 1rem;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    font-size: 0.8125rem;
    color: #4b5563;
}

[data-bs-theme="dark"] .code-explanation {
    background: #161b22;
    border-color: #30363d;
    color: #8b949e;
}

/* Code Tabs (R / Python) */
.code-tabs {
    border-bottom: none;
    background: #161b22;
    padding: 0 1rem;
    display: flex;
    gap: 0.25rem;
}

.code-tabs .nav-link {
    color: #8b949e;
    border: none;
    border-radius: 6px 6px 0 0;
    padding: 0.625rem 1rem;
    font-weight: 500;
    font-size: 0.8125rem;
    background: transparent;
    transition: color 0.15s, background 0.15s;
}

.code-tabs .nav-link:hover {
    color: #e6edf3;
    background: rgba(255, 255, 255, 0.05);
}

.code-tabs .nav-link.active {
    color: #e6edf3;
    background: #0d1117;
}

/* ==================== Exercises ==================== */

.exercise-card {
    border: 1px solid #E2E8F0;
    border-radius: var(--border-radius);
    margin: 2rem 0;
    overflow: hidden;
    background: white;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-normal);
}

.exercise-card:hover {
    box-shadow: var(--shadow-md);
}

[data-bs-theme="dark"] .exercise-card {
    background: #161B22;
    border-color: #30363D;
}

.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, #F8FAFC 0%, #F1F5F9 100%);
    border-bottom: 1px solid #E2E8F0;
}

[data-bs-theme="dark"] .exercise-header {
    background: linear-gradient(135deg, #21262D 0%, #161B22 100%);
    border-color: #30363D;
}

.exercise-number {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    color: var(--accent-teal);
    display: block;
    margin-bottom: 0.25rem;
}

.exercise-title {
    font-weight: 700;
    font-size: 1.0625rem;
    color: var(--mlb-navy);
}

[data-bs-theme="dark"] .exercise-title {
    color: #F0F6FC;
}

.exercise-body {
    padding: 1.5rem;
}

.hints-content {
    background: linear-gradient(135deg, #FFFBEB, #FEF3C7);
    padding: 1.25rem;
    border-radius: var(--border-radius-sm);
    border-left: 4px solid var(--warning);
    margin-top: 1rem;
}

[data-bs-theme="dark"] .hints-content {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.08));
    color: #E6EDF3;
}

[data-bs-theme="dark"] .hints-content p {
    color: #C9D1D9;
}

/* ==================== Tables ==================== */

.chapter-content table {
    width: 100%;
    margin: 2rem 0;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid #E2E8F0;
}

[data-bs-theme="dark"] .chapter-content table {
    border-color: #30363D;
}

.chapter-content th,
.chapter-content td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #E2E8F0;
    text-align: left;
}

[data-bs-theme="dark"] .chapter-content th,
[data-bs-theme="dark"] .chapter-content td {
    border-color: #30363D;
}

.chapter-content th {
    background: linear-gradient(180deg, #F8FAFC 0%, #F1F5F9 100%);
    font-weight: 700;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mlb-navy);
}

[data-bs-theme="dark"] .chapter-content th {
    background: linear-gradient(180deg, #21262D 0%, #161B22 100%);
    color: #F0F6FC;
}

.chapter-content tr:last-child td {
    border-bottom: none;
}

.chapter-content tbody tr {
    transition: background var(--transition-fast);
}

.chapter-content tbody tr:hover {
    background: #F8FAFC;
}

[data-bs-theme="dark"] .chapter-content tbody tr:hover {
    background: #21262D;
}

[data-bs-theme="dark"] .chapter-content td {
    color: #C9D1D9;
}

/* ==================== Hero Section ==================== */

.hero-section {
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-blue) 50%, #0A4F9C 100%);
    color: white;
    padding: 6rem 0;
    margin-top: calc(-1 * var(--header-height));
    padding-top: calc(6rem + var(--header-height));
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.5;
}

.hero-section > * {
    position: relative;
    z-index: 1;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.text-gradient {
    background: linear-gradient(135deg, #FFFFFF, #A5D8FF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.375rem;
    font-weight: 400;
    opacity: 0.9;
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.hero-stats {
    display: flex;
    gap: 3rem;
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.375rem;
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Code Preview in Hero */
.code-preview {
    background: var(--code-bg);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.code-preview-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    background: #2D3748;
}

.code-preview-header .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.red { background: #FF5F56; }
.dot.yellow { background: #FFBD2E; }
.dot.green { background: #27C93F; }

.code-preview-header .filename {
    margin-left: auto;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    opacity: 0.6;
}

.code-preview pre {
    margin: 0;
    padding: 1.5rem;
    font-size: 0.85rem;
    overflow-x: auto;
}

/* ==================== Feature Cards ==================== */

.feature-card {
    background: white;
    padding: 2.5rem 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
    height: 100%;
    transition: all var(--transition-normal);
    border: 1px solid transparent;
}

.feature-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl);
    border-color: var(--mlb-blue);
}

[data-bs-theme="dark"] .feature-card {
    background: #161B22;
    border-color: #30363D;
}

[data-bs-theme="dark"] .feature-card:hover {
    border-color: #58A6FF;
}

.feature-icon {
    font-size: 3rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--mlb-blue), var(--accent-teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.feature-icon i + i {
    margin-left: 0.5rem;
}

.feature-card h4 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.feature-card p {
    color: #64748B;
    font-size: 0.9375rem;
    margin-bottom: 0;
}

[data-bs-theme="dark"] .feature-card p {
    color: #B0BAC5;
}

/* ==================== Chapter Cards ==================== */

.chapter-card-link {
    text-decoration: none;
    color: inherit;
}

.chapter-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1.75rem;
    height: 100%;
    box-shadow: var(--shadow-sm);
    border: 1px solid #E2E8F0;
    transition: all var(--transition-normal);
}

.chapter-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--mlb-blue);
}

[data-bs-theme="dark"] .chapter-card {
    background: #161B22;
    border-color: #30363D;
}

[data-bs-theme="dark"] .chapter-card:hover {
    border-color: #58A6FF;
}

.chapter-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}

.chapter-number-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--mlb-blue), var(--mlb-navy));
    color: white;
    font-weight: 800;
    border-radius: var(--border-radius-sm);
    font-size: 1.25rem;
    box-shadow: var(--shadow-md);
}

.chapter-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.chapter-time {
    font-size: 0.8rem;
    color: #64748B;
    font-weight: 500;
}

.chapter-card-title {
    font-size: 1.125rem;
    margin-bottom: 0.75rem;
    color: var(--mlb-navy);
    font-weight: 700;
}

[data-bs-theme="dark"] .chapter-card-title {
    color: #F0F6FC;
}

.chapter-card-description {
    font-size: 0.9375rem;
    color: #64748B;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

[data-bs-theme="dark"] .chapter-card-description {
    color: #B0BAC5;
}

.chapter-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.25rem;
    border-top: 1px solid #E2E8F0;
    font-size: 0.875rem;
}

[data-bs-theme="dark"] .chapter-card-footer {
    border-color: #30363D;
}

.section-count {
    color: #64748B;
    font-weight: 500;
}

[data-bs-theme="dark"] .section-count {
    color: #A8B2C1;
}

[data-bs-theme="dark"] .chapter-time {
    color: #A8B2C1;
}

.read-more {
    color: var(--mlb-blue);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

[data-bs-theme="dark"] .read-more {
    color: #58A6FF;
}

.read-more i {
    transition: transform var(--transition-fast);
}

.chapter-card:hover .read-more i {
    transform: translateX(4px);
}

/* ==================== Language Cards ==================== */

.language-card {
    background: white;
    border-radius: var(--border-radius-lg);
    padding: 2.5rem;
    height: 100%;
    box-shadow: var(--shadow-md);
    border: 1px solid transparent;
    transition: all var(--transition-normal);
}

.language-card:hover {
    box-shadow: var(--shadow-lg);
}

[data-bs-theme="dark"] .language-card {
    background: #161B22;
    border-color: #30363D;
}

.language-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.language-header i {
    font-size: 3rem;
}

.language-r .language-header i {
    color: var(--code-r);
}

.language-python .language-header i {
    color: var(--code-python);
}

.language-features {
    list-style: none;
    padding: 0;
    margin: 1.25rem 0 0;
}

.language-features li {
    padding: 0.75rem 0;
    border-bottom: 1px solid #E2E8F0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

[data-bs-theme="dark"] .language-features li {
    border-color: #30363D;
    color: #C9D1D9;
}

.language-features li:last-child {
    border-bottom: none;
}

.language-features li::before {
    content: '✓';
    color: var(--success);
    font-weight: 700;
}

.language-features code {
    font-weight: 600;
    font-size: 0.875em;
}

/* ==================== CTA Section ==================== */

.cta-section {
    background: linear-gradient(135deg, var(--mlb-navy) 0%, var(--mlb-blue) 100%);
    color: white;
    position: relative;
    overflow: hidden;
}

.cta-section::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -25%;
    width: 80%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
}

/* ==================== Glossary ==================== */

.letter-heading {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--mlb-blue);
    padding-bottom: 0.75rem;
    border-bottom: 3px solid var(--mlb-blue);
    margin-bottom: 1.5rem;
    display: inline-block;
}

.glossary-term-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid #E2E8F0;
    height: 100%;
    transition: all var(--transition-fast);
}

.glossary-term-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--mlb-blue);
}

[data-bs-theme="dark"] .glossary-term-card {
    background: #161B22;
    border-color: #30363D;
}

[data-bs-theme="dark"] .glossary-term-card:hover {
    border-color: #58A6FF;
}

.term-name {
    font-size: 1.0625rem;
    font-weight: 700;
    margin-bottom: 0.625rem;
    color: var(--mlb-navy);
}

[data-bs-theme="dark"] .term-name {
    color: #F0F6FC;
}

.term-definition {
    font-size: 0.9375rem;
    color: #64748B;
    line-height: 1.6;
}

[data-bs-theme="dark"] .term-definition {
    color: #B0BAC5;
}

.term-formula code {
    background: linear-gradient(135deg, rgba(0, 45, 114, 0.1), rgba(0, 45, 114, 0.05));
    padding: 0.375rem 0.75rem;
    border-radius: var(--border-radius-sm);
    display: inline-block;
    margin-top: 0.5rem;
}

.alphabet-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.alphabet-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: var(--border-radius-sm);
    font-weight: 700;
    font-size: 0.875rem;
    color: #475569;
    transition: all var(--transition-fast);
}

[data-bs-theme="dark"] .alphabet-link {
    background: #161B22;
    border-color: #30363D;
    color: #B0BAC5;
}

.alphabet-link:hover {
    background: var(--mlb-blue);
    border-color: var(--mlb-blue);
    color: white;
    transform: scale(1.1);
}

/* ==================== Search Results ==================== */

.search-results-list .search-result-item {
    padding: 1.5rem;
    border: 1px solid #E2E8F0;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    background: white;
    transition: all var(--transition-fast);
}

.search-results-list .search-result-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--mlb-blue);
}

[data-bs-theme="dark"] .search-results-list .search-result-item {
    background: #161B22;
    border-color: #30363D;
}

.result-title a {
    font-weight: 700;
    font-size: 1.125rem;
}

.result-meta {
    margin: 0.625rem 0;
}

.result-excerpt {
    color: #64748B;
    font-size: 0.9375rem;
    margin-bottom: 0;
    line-height: 1.6;
}

[data-bs-theme="dark"] .result-excerpt {
    color: #B0BAC5;
}

/* ==================== Blockquotes / Callouts ==================== */

blockquote,
.callout {
    background: linear-gradient(135deg, #F0F9FF, #E0F2FE);
    border-left: 4px solid var(--mlb-blue);
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
    font-style: italic;
}

[data-bs-theme="dark"] blockquote,
[data-bs-theme="dark"] .callout {
    background: linear-gradient(135deg, rgba(88, 166, 255, 0.12), rgba(88, 166, 255, 0.06));
    color: #C9D1D9;
}

[data-bs-theme="dark"] blockquote p,
[data-bs-theme="dark"] .callout p {
    color: #C9D1D9;
}

/* ==================== Footer ==================== */

.site-footer {
    background: linear-gradient(180deg, var(--mlb-navy) 0%, #020617 100%);
    color: white;
    padding: 4rem 0 2rem;
}

.footer-title {
    font-size: 1.375rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.footer-subtitle {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 1.25rem;
    opacity: 0.6;
    font-weight: 600;
}

.footer-links li {
    margin-bottom: 0.625rem;
}

.footer-links a {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9375rem;
    transition: all var(--transition-fast);
}

.footer-links a:hover {
    color: white;
    padding-left: 0.25rem;
}

.footer-divider {
    border-color: rgba(255, 255, 255, 0.1);
    margin: 2.5rem 0 1.5rem;
}

.footer-bottom {
    font-size: 0.875rem;
    opacity: 0.6;
}

/* Footer dark mode - ensure proper contrast */
.site-footer .text-muted {
    color: rgba(255, 255, 255, 0.65) !important;
}

.site-footer a {
    color: rgba(255, 255, 255, 0.7);
}

.site-footer a:hover {
    color: #FFFFFF;
}

/* ==================== Responsive ==================== */

@media (max-width: 1199.98px) {
    .page-toc-wrapper {
        display: none;
    }
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .chapter-content-wrapper {
        margin-left: 0;
    }

    .toc-list {
        columns: 1;
    }

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

    .hero-stats {
        gap: 2rem;
    }

    .stat-number {
        font-size: 2rem;
    }
}

@media (max-width: 767.98px) {
    .hero-section {
        padding: 4rem 0;
        padding-top: calc(4rem + var(--header-height));
    }

    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 1.125rem;
    }

    .hero-stats {
        flex-wrap: wrap;
        gap: 1.5rem;
    }

    .stat-item {
        flex: 1 0 40%;
    }

    h1 { font-size: 2rem; }
    h2 { font-size: 1.5rem; }

    .feature-card {
        padding: 2rem 1.5rem;
    }

    #globalSearch {
        width: 150px;
    }

    #globalSearch:focus {
        width: 200px;
    }
}

/* ==================== Print Styles ==================== */

@media print {
    .navbar,
    .sidebar,
    .sidebar-toggle,
    .page-toc-wrapper,
    .chapter-nav,
    .reading-progress,
    .btn-copy,
    .code-tabs {
        display: none !important;
    }

    .chapter-content-wrapper {
        margin: 0 !important;
    }

    body {
        font-size: 11pt;
        background: white;
        color: black;
    }

    .chapter-content {
        max-width: 100%;
    }

    pre {
        white-space: pre-wrap;
        word-break: break-all;
        font-size: 9pt;
        border: 1px solid #ccc;
        padding: 1rem;
    }

    a {
        color: black;
        text-decoration: underline;
    }

    h2::after {
        display: none;
    }

    .exercise-card {
        page-break-inside: avoid;
    }
}

/* ==================== Prism.js Font Override ==================== */

:not(pre) > code,
pre,
pre > code,
code[class*="language-"],
pre[class*="language-"],
pre[class*="language-"] *,
.token,
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata,
.token.punctuation,
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted,
.token.operator,
.token.entity,
.token.url,
.token.atrule,
.token.attr-value,
.token.keyword,
.token.function,
.token.regex,
.token.important,
.token.variable,
.token.deleted {
    font-family: 'Fira Code', 'JetBrains Mono', 'Consolas', 'Monaco', monospace !important;
}

/* Inline code in content */
.section-content code,
.chapter-content code,
.exercise-description code {
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace !important;
    font-size: 0.875em;
    background: linear-gradient(135deg, rgba(0, 45, 114, 0.08), rgba(0, 45, 114, 0.04));
    color: var(--mlb-navy);
    padding: 0.2em 0.5em;
    border-radius: 6px;
    border: 1px solid rgba(0, 45, 114, 0.1);
}

[data-bs-theme="dark"] .section-content code,
[data-bs-theme="dark"] .chapter-content code,
[data-bs-theme="dark"] .exercise-description code {
    background: linear-gradient(135deg, rgba(99, 179, 237, 0.15), rgba(99, 179, 237, 0.08));
    color: #7DD3FC;
    border-color: rgba(99, 179, 237, 0.2);
}

/* ==================== Utility Classes ==================== */

.bg-gradient-primary {
    background: linear-gradient(135deg, var(--mlb-navy), var(--mlb-blue)) !important;
}

.text-gradient-primary {
    background: linear-gradient(135deg, var(--mlb-blue), var(--accent-teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.btn-primary {
    background: linear-gradient(135deg, var(--mlb-blue), var(--mlb-navy));
    border: none;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--mlb-navy), var(--mlb-blue));
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-outline-primary {
    border: 2px solid var(--mlb-blue);
    color: var(--mlb-blue);
    font-weight: 600;
    padding: 0.625rem 1.375rem;
    border-radius: var(--border-radius-sm);
    background: transparent;
    transition: all var(--transition-fast);
}

.btn-outline-primary:hover {
    background: var(--mlb-blue);
    color: white;
    transform: translateY(-2px);
}

[data-bs-theme="dark"] .btn-outline-primary {
    border-color: #58A6FF;
    color: #58A6FF;
}

[data-bs-theme="dark"] .btn-outline-primary:hover {
    background: #58A6FF;
    border-color: #58A6FF;
    color: #0D1117;
}

/* Focus states for accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
.btn:focus-visible {
    outline: 2px solid #58A6FF;
    outline-offset: 2px;
}

[data-bs-theme="dark"] a:focus-visible,
[data-bs-theme="dark"] button:focus-visible {
    outline-color: #79B8FF;
}

/* Smooth scroll target offset for fixed header */
:target {
    scroll-margin-top: calc(var(--header-height) + 2rem);
}
