@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
    /* Premium Cyber-Minimalist Theme - Dull White */
    --bg-base: #c5cad1;
    --bg-surface: #d1d6da;
    --bg-panel: rgba(241, 245, 249, 0.95);
    --text-main: #182231;
    --text-muted: #64748b;
    --accent-primary: #1e293b;
    --accent-hover: #0f172a;
    --accent-hover-bg: rgba(15, 23, 42, 0.08);
    --accent-blue: #0f172a;
    --accent-success: #10b981;
    --border-light: rgba(148, 163, 184, 0.2);
    --border-highlight: rgba(15, 23, 42, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', monospace;

    /* Code Block Colors */
    --bg-code: #1e293b;
    --text-code: #e2e8f0;

    /* Callout Colors */
    --bg-note: #f1f5f9;
    --border-note: #cbd5e1;
    --text-note: #0f172a;
    
    --bg-tip: #f0fdf4;
    --border-tip: #bbf7d0;
    --text-tip: #166534;
    
    --bg-warning: #fffbeb;
    --border-warning: #fef3c7;
    --text-warning: #92400e;
    
    --bg-important: #faf5ff;
    --border-important: #e9d5ff;
    --text-important: #6b21a8;
    
    --bg-caution: #fef2f2;
    --border-caution: #fecaca;
    --text-caution: #991b1b;

    /* Footer & Overlays */
    --bg-footer: #13161f;
    --text-footer: #94a3b8;
    --border-xray: rgba(0, 0, 0, 0.4);

    /* Graph Colors */
    /* Technical Graphs Color Palette */
    --graph-curve: #6366f1;     /* Indigo-500 */
    --graph-accent: #f43f5e;    /* Rose-500 */
    --graph-secondary: #0ea5e9; /* Sky-500 */
    --graph-error: #ef4444;     /* Red-500 */
    --graph-bg: #f8fafc;        /* Slate-50 */
    --graph-axis: #475569;      /* Slate-600 */
}

/* Visualization Styles */
.theory-box.graph-container {
    background: #f8fafc !important; /* Explicitly light for graphs */
    border-radius: 20px;
    padding: 3rem 2rem;
    margin: 2.5rem 0;
    border: 1px solid var(--border-light);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible; /* Ensure labels aren't clipped */
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 1;
}

.technical-graph {
    width: 100%;
    max-width: 500px;
    height: auto;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.05));
    overflow: visible;
}

.technical-graph text {
    fill: #475569 !important; /* Force slate-600 */
    font-family: var(--font-ui);
    user-select: none;
}

.technical-graph line, 
.technical-graph path {
    vector-effect: non-scaling-stroke;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html {
    height: 100%;
    scroll-behavior: auto;
    overflow: hidden;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-base);
    color: var(--text-main);
    height: 100%;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    width: 100%;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.2); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}


/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 2rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    z-index: 1000;
    flex-shrink: 0;
    min-height: 70px;
    width: 100%;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    position: sticky;
    top: 0;
}


/* ─── Header Flex Rows ────────────────────────────── */
.header-left { display: flex; align-items: center; gap: 1.5rem; flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 1rem; flex-shrink: 0; }


.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-logo { 
    width: 38px; 
    height: 38px; 
    object-fit: contain; 
    border-radius: 5px;
    background: white; /* ensures it looks clean if there's any transparency or different header color */
    padding: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.brand-text { display: flex; flex-direction: column; overflow: hidden; }

.brand-title { font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; color: var(--text-main); }
.brand-subtitle { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); font-weight: 600; }

.menu-toggle {
    background: #f1f5f9;
    border: 1px solid var(--border-light);
    color: var(--text-main);
    padding: 0.6rem 1.25rem;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 0.85rem;
    transition: var(--transition);
}

.menu-toggle:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-1px);
}

.search-btn-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
}

.search-btn-header:hover {
    background: rgba(15, 23, 42, 0.05);
    color: var(--text-main);
}

.search-btn-header kbd {
    background: rgba(15, 23, 42, 0.08);
    border: none;
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
    border-radius: 4px;
    color: inherit;
    font-family: var(--font-ui);
    font-weight: 700;
    margin-left: 0.2rem;
}

/* Layout */
.book-layout {
    display: flex;
    flex: 1;
    height: 0; /* force flex child to not grow beyond parent */
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0;
    transform: translateY(10px);
    width: 100%;        /* always fill full viewport width */
    overflow: hidden;
}

.book-layout.loaded { opacity: 1; transform: translateY(0); }

/* Sidebars */
.left-sidebar, .right-sidebar {
    width: 240px;
    padding: 2rem 1.25rem;
    height: 100%;
    overflow-y: auto;
    flex-shrink: 0;
}

.left-sidebar { border-right: 1px solid var(--border-light); }
.right-sidebar { border-left: 1px solid var(--border-light); }

.sidebar-title {
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-main);
    margin-bottom: 1.5rem;
}

/* In-Page TOC styles */
.in-page-toc-item {
    display: block;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 0.4rem 0;
    transition: var(--transition);
    line-height: 1.4;
}

.in-page-toc-item:hover { color: var(--accent-primary); }
.in-page-toc-item.toc-h2 { font-weight: 600; margin-top: 0.5rem; }
.in-page-toc-item.toc-h3 { padding-left: 1rem; font-size: 0.8rem; }

/* ─── Responsive: Tablet (≤ 1024px) ─────────────────────────────── */
@media (min-width: 1025px) {
    .menu-toggle { display: none; }
}

@media (max-width: 1024px) {
    .left-sidebar, .right-sidebar { display: none; }
    .menu-toggle { display: flex; }
    .theory-pane { padding: 2rem 1.5rem; }
    .theory-inner { max-width: 100%; min-width: 0; }
    .theory-title { font-size: 2.2rem; margin-bottom: 1.5rem; }
}

/* ─── Responsive: Mobile (≤ 640px) ──────────────────────────────── */
@media (max-width: 640px) {
    /* Revert locked viewport so footer is visible when page ends */
    html {
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }
    body {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: auto;
    }
    #app {
        height: auto;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        overflow: visible;
    }
    .book-layout {
        height: auto;
        min-height: calc(100vh - 60px); /* Fill space between header and footer */
        overflow: visible;
        flex-direction: column;
        flex: 1 0 auto;
    }
    .theory-pane {
        height: auto;
        min-height: 400px;
        overflow: visible;
        padding: 1.25rem 0.75rem;
        flex: 1;
    }

    /* Header — stays a SINGLE ROW */
    header {
        padding: 0.6rem 0.875rem;
        min-height: auto;
    }
    .header-left { gap: 0.4rem; }
    .header-right { gap: 0.4rem; }
    
    .brand-title { font-size: 0.95rem; }
    .brand-subtitle { display: none; }

    /* Collapse menu-toggle to icon-only square */
    .menu-toggle {
        padding: 0;
        width: 40px;
        height: 40px;
        min-width: 40px;
        justify-content: center;
        border-radius: 10px;
        flex-shrink: 0;
    }
    .menu-toggle span { display: none; }

    /* Brand stays inline beside the icon */
    .brand-logo { width: 30px; height: 30px; border-radius: 4px; }
    .brand-title { font-size: 1rem; white-space: nowrap; }
    .brand-subtitle { font-size: 0.6rem; white-space: nowrap; }

    /* Search button — icon + text, no kbd */
    .search-btn-header { padding: 0.5rem 0.6rem; font-size: 0.8rem; }
    .search-btn-header kbd { display: none; }
    .search-btn-header span { display: none; } /* Hide 'Search' text on very small screens */
    
    @media (min-width: 480px) {
        .search-btn-header span { display: inline; }
    }

    /* Theory content area typography */
    .theory-title {
        font-size: 1.75rem;
        margin-bottom: 0.875rem;
        word-break: break-word;
    }
    .theory-content {
        font-size: 0.95rem;
        line-height: 1.75;
        overflow-wrap: break-word;
        word-break: break-word;
    }
    .theory-content h2 { font-size: 1.35rem; margin: 2rem 0 0.875rem; }
    .theory-content h3 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }
    .theory-content pre, .theory-content code {
        white-space: pre-wrap;
        word-break: break-word;
        font-size: 0.8rem;
    }
    .mermaid { padding: 1rem !important; border-radius: 0.75rem !important; margin: 1.25rem 0; overflow-x: auto; }
    .theory-content pre { padding: 1rem !important; border-radius: 0.75rem !important; overflow-x: auto; }

    /* Footer visible on mobile at end of page */
    .app-footer {
        padding: 1.5rem 1rem;
        flex-shrink: 0;
    }
    .footer-content { flex-direction: column !important; gap: 0.5rem; text-align: center; justify-content: center !important; }
    .footer-divider { display: none; }
}


/* Panes */
.theory-pane {
    flex: 1;
    min-width: 0;
    background: var(--bg-surface);
    position: relative;
    padding: 2.5rem 2.5rem;  /* reduced from 3rem 4rem */
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
}

/* Theory Content */
.theory-inner { max-width: 1000px; margin: 0 auto; min-width: 0; }

.theory-title { font-size: 2.2rem; font-weight: 900; letter-spacing: -0.04em; margin-bottom: 2rem; color: var(--accent-primary); }

.theory-content { font-size: 1.05rem; line-height: 1.7; color: var(--text-main); font-weight: 400; }
.theory-content h2 { font-size: 1.6rem; font-weight: 800; margin: 2.5rem 0 1.25rem; letter-spacing: -0.02em; border-bottom: 1px solid var(--border-light); padding-bottom: 0.5rem; }
.theory-content h3 { font-size: 1.2rem; font-weight: 700; margin: 1.75rem 0 0.85rem; color: var(--accent-primary); }
.theory-content p { margin-bottom: 1.25rem; }
.theory-content ul, .theory-content ol { margin-bottom: 1.25rem; padding-left: 1.5rem; }
.theory-content li { margin-bottom: 0.4rem; }

/* Visualization & Theory Boxes */
.graph-container {
    background: #ffffff !important; /* Force white background for all graphs */
    padding: 3rem 2rem !important;
    border-radius: 20px !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-premium) !important;
    margin: 3rem 0;
    overflow: visible !important; /* Prevent label clipping */
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 10;
}

.technical-graph {
    width: 100%;
    max-width: 500px;
    height: auto;
    overflow: visible;
}

.technical-graph text {
    fill: #1e293b !important; /* Force Slate-800 for visibility */
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
}

.technical-graph line[stroke="currentColor"],
.technical-graph path[stroke="currentColor"] {
    stroke: #475569 !important; /* Force Slate-600 for axes */
}

.technical-graph line, 
.technical-graph path,
.technical-graph circle {
    vector-effect: non-scaling-stroke;
}

.mermaid {
    background: #ffffff !important;
    padding: 2.5rem !important;
    border-radius: 1.5rem !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-premium) !important;
    margin: 3rem 0;
    overflow-x: auto !important;
}

.theory-content pre {
    background: var(--bg-code) !important;
    padding: 2rem !important;
    border-radius: 1rem !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-premium) !important;
    margin: 3rem 0;
    overflow-x: auto !important;
}

.theory-content pre code {
    color: var(--text-code) !important;
    text-shadow: none !important;
}

.theory-content blockquote {
    background: var(--bg-panel);
    border-left: 4px solid var(--accent-primary);
    padding: 1.5rem 2rem;
    border-radius: 0 1rem 1rem 0;
    margin: 2.5rem 0;
    font-style: italic;
    color: var(--text-muted);
}

/* Callouts */
.callout {
    padding: 1.5rem 2rem;
    border-radius: 1.25rem;
    margin: 2.5rem 0;
    border: 1px solid transparent;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* ─── Tables ────────────────────────────────────────────────── */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 2.5rem 0;
    border-radius: 16px;
    border: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.4);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.theory-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.theory-content th, 
.theory-content td {
    padding: 1.25rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.theory-content th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--accent-primary);
    white-space: nowrap;
}

.theory-content tr:last-child td { border-bottom: none; }
.theory-content td { color: var(--text-main); line-height: 1.5; }

@media (max-width: 640px) {
    .table-wrapper { margin: 2rem 0; border-radius: 12px; }
    .theory-content table { min-width: 650px; }
    .theory-content td, .theory-content th { padding: 1rem !important; min-width: 150px; }
}

/* ─── Callouts ─────────────────────────────────────────────── */
.callout-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
}

.callout-note { background: var(--bg-note); border-color: var(--border-note); color: var(--text-note); }
.callout-tip { background: var(--bg-tip); border-color: var(--border-tip); color: var(--text-tip); }
.callout-warning { background: var(--bg-warning); border-color: var(--border-warning); color: var(--text-warning); }
.callout-important { background: var(--bg-important); border-color: var(--border-important); color: var(--text-important); }
.callout-caution { background: var(--bg-caution); border-color: var(--border-caution); color: var(--text-caution); }

/* Navigation Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    display: flex;
}

.sidebar-overlay.active { opacity: 1; pointer-events: all; }

.menu-container {
    width: 420px;
    height: 100%;
    background: var(--bg-surface);
    box-shadow: 20px 0 50px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: var(--transition);
    padding: 3rem 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

@media (max-width: 640px) {
    .menu-container { width: 100%; padding: 4rem 1.5rem 2rem; }
}

.sidebar-overlay.active .menu-container { transform: translateX(0); }


.close-menu {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.close-menu:hover { color: var(--accent-primary); transform: rotate(90deg); }

#menu-content::before {
    content: 'Curriculum';
    display: block;
    font-size: 1.5rem;
    font-weight: 900;
    margin-bottom: 2.5rem;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.menu-category { margin-bottom: 0.5rem; }
.menu-category-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 800;
    color: var(--text-muted);
    padding: 0.75rem 0.5rem;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: color 0.2s;
}

.menu-category-title:hover {
    color: var(--text-main);
}

.menu-category-title i {
    transition: transform 0.3s ease;
    width: 14px;
    height: 14px;
}

.menu-category.open .menu-category-title i {
    transform: rotate(180deg);
}

.menu-topics {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.menu-topics-inner {
    min-height: 0;
    padding: 0.5rem 0;
}

.menu-category.open .menu-topics {
    grid-template-rows: 1fr;
}


.menu-item {
    display: block;
    padding: 0.75rem 1rem;
    margin: 2px 0;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.menu-item:hover { 
    background: var(--accent-hover-bg); 
    padding-left: 1.25rem; 
    color: var(--accent-primary);
}
.menu-item.active { 
    background: transparent; 
    color: var(--text-main) !important; 
    border: 1.5px solid var(--text-main);
    box-shadow: none; 
}


/* Command Palette */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
    z-index: 3000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--bg-surface);
    width: 600px;
    max-width: 90%;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: var(--transition);
}


.modal.active .modal-content { transform: scale(1); }

.cmd-input-wrapper {
    display: flex;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.cmd-input-wrapper i { color: var(--text-muted); width: 20px; }

#cmd-palette-input {
    width: 100%;
    border: none;
    outline: none;
    padding-left: 1rem;
    font-size: 1.1rem;
    font-family: var(--font-ui);
    color: var(--text-main);
    background: transparent;
}

.cmd-results { max-height: 400px; overflow-y: auto; padding: 0.5rem; }
.single-week {
    display: flex;
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0;
    padding: 0.85rem 1.25rem !important;
    margin-bottom: 0.2rem;
}

.week-num {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    line-height: 1.1;
}

.week-title {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.1;
}

.menu-category-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cat-label-group {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.cmd-item {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.cmd-item:hover, .cmd-item.selected { background: var(--bg-panel); }
.cmd-title { font-weight: 600; color: var(--text-main); }
.cmd-cat { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.cmd-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.5rem 1.25rem;
    margin-top: 0.5rem;
}


.cmd-footer {
    padding: 0.75rem 1.5rem;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.cmd-footer span { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
kbd {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.6rem;
}

/* Footer */
.app-footer {
    background: var(--bg-footer);
    color: var(--text-footer);
    padding: 0.75rem 2rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.footer-content { display: flex; align-items: center; justify-content: center; gap: 1.5rem; }
.footer-divider { width: 1px; height: 12px; background: rgba(255,255,255,0.1); }

@media (max-width: 640px) {
    .app-footer { padding: 1.5rem 1rem; }
    .footer-content { flex-direction: column; gap: 0.75rem; text-align: center; }
    .footer-divider { display: none; }
}


/* Progress Tracking */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent-primary);
    color: white;
    padding: 1rem 2rem;
    border-radius: 2rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 4000;
    transition: var(--transition);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast.visible { transform: translateX(-50%) translateY(0); }

/* X-Ray Variable Tooltips */
.xray-var {
    border-bottom: 2px dashed var(--border-xray);
    cursor: help;
    position: relative;
    transition: var(--transition);
}

.xray-var:hover { 
    background: var(--bg-panel); 
    border-bottom-color: var(--text-main); 
    text-shadow: 0 2px 4px rgba(100, 116, 139, 0.5);
}

/* Shared fixed-position tooltip — escapes all container clipping */
#xray-tooltip {
    position: fixed;
    z-index: 9999;
    width: 280px;
    background: var(--bg-footer);
    color: #f1f5f9;
    padding: 0.9rem 1.1rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: normal;
    line-height: 1.55;
    text-align: left;
    box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(4px);
}

#xray-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Home Mode */
.book-layout.home-mode .right-sidebar {
    display: none;
}

.book-layout.home-mode .theory-pane {
    max-width: 1200px;
    margin: 0 auto;
    background: transparent;
    box-shadow: none;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%; /* Vertical centering */
}

@media (max-width: 1024px) {
    .book-layout.home-mode .theory-pane { margin: 2rem auto; max-width: 95%; }
}

@media (max-width: 640px) {
    .book-layout.home-mode .theory-pane { margin: 1rem auto; max-width: 100%; }
}


.home-card {
    background: var(--bg-panel);
    border-radius: 32px;
    padding: 8rem 6rem;
    text-align: center;
    width: 100%;
    max-width: 1000px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-light);
}

@media (max-width: 640px) {
    .home-card { padding: 3rem 1.25rem; border-radius: 16px; margin: 1.5rem 0.75rem; width: auto; }
    .home-title { font-size: clamp(1.8rem, 12vw, 2.5rem); letter-spacing: -0.01em; }
    .home-subtitle { font-size: 0.8rem; margin-bottom: 2rem; }
    .home-actions { flex-direction: column; width: 100%; gap: 0.75rem; }
    .home-actions button { width: 100%; padding: 0.875rem; font-size: 0.9rem; }
    .home-actions kbd { display: none; }
    
    .network-svg { opacity: 0.15; }
}


@keyframes pulse-node {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.3); opacity: 1; }
}

@keyframes flow-line {
    0% { stroke-dashoffset: 100; opacity: 0.2; }
    50% { opacity: 0.5; }
    100% { stroke-dashoffset: 0; opacity: 0.2; }
}

.network-svg circle {
    transform-origin: center;
    animation: pulse-node 4s infinite ease-in-out;
}

.network-path {
    stroke: rgba(148, 163, 184, 0.4);
    stroke-width: 1.5;
    stroke-dasharray: 100;
    animation: flow-line 10s linear infinite;
}

.home-content-wrapper {
    position: relative;
    z-index: 10;
}

.home-title {
    font-size: clamp(2rem, 10vw, 3.5rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    line-height: 1.1;
    overflow-wrap: break-word;
}

.home-subtitle {
    font-size: 0.9rem;
    font-family: var(--font-mono);
    color: var(--text-main);
    letter-spacing: 0.1em;
    margin-bottom: 3.5rem;
    text-transform: uppercase;
    font-weight: 600;
}

.home-actions {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    align-items: center;
}

/* Home Page Note */
.home-note {
    max-width: 700px;
    margin: 4rem auto 0;
    padding: 1.75rem 2.5rem;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.02) 0%, rgba(15, 23, 42, 0.05) 100%);
    border: 1px solid var(--border-light);
    border-radius: 24px;
    text-align: center;
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0,0,0,0.02);
}

.home-note-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--accent-primary);
    margin-bottom: 0.75rem;
    opacity: 0.9;
}

.home-note p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-muted);
    margin: 0;
    font-weight: 500;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.9rem 2.2rem;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.15);
}

.btn-secondary {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 0.9rem 1.8rem;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: rgba(15, 23, 42, 0.03);
    border-color: var(--text-muted);
}

.btn-secondary kbd {
    background: rgba(15, 23, 42, 0.06);
    border: none;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    margin-left: 0.5rem;
    color: var(--text-muted);
}
/* Page Navigation Buttons */
.page-navigation {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
}

/* Footer */
.app-footer {
    background: var(--bg-footer);
    color: var(--text-footer);
    padding: 0.5rem 2rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    z-index: 1000;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.footer-branding {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.8;
}

.author-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.author-name {
    color: white;
    font-weight: 800;
}

@media (max-width: 640px) {
    .app-footer { padding: 1.5rem 1rem; }
    .footer-content {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
}

.nav-button {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
}

.nav-button:hover {
    border-color: var(--accent-primary);
    background: var(--bg-panel);
    transform: translateY(-2px);
    box-shadow: var(--shadow-premium);
}

.nav-button.next {
    justify-content: flex-end;
    text-align: right;
}

.nav-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.nav-title {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-main);
}

.nav-button i {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    transition: var(--transition);
}

.nav-button:hover i {
    color: var(--accent-primary);
}

.nav-placeholder {
    flex: 1;
}

@media (max-width: 640px) {
    .page-navigation {
        flex-direction: column;
    }
}

/* Formula Boxes */
.formula-box {
    background: rgba(15, 23, 42, 0.03);
    border-left: 4px solid var(--accent-primary);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 2rem 0;
    display: block;
    box-shadow: var(--shadow-premium);
    overflow-x: auto;
}
