:root {
    --bg-color: #02040a;
    --sidebar-bg: #0a0f1d;
    --accent-color: #00f2ff;
    --accent-gradient: linear-gradient(135deg, #00f2ff 0%, #7000ff 100%);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --card-bg: rgba(15, 23, 42, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(20px);
    --font-heading: 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    --transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}



* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
    -webkit-text-size-adjust: 100%;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: 
        radial-gradient(circle at 0% 0%, rgba(0, 242, 255, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(112, 0, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-color);
}

/* Layout */
.app-container {
    display: block;
    min-height: 100vh;
}

/* Sidebar */
aside.sidebar {
    width: 320px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 2rem;
    padding-top: calc(2rem + env(safe-area-inset-top, 0px));
    overflow-y: auto;
    z-index: 1000;
    transition: var(--transition);
    max-width: 100vw;
}

.logo-area {
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.logo-icon-img {
    width: 60px;
    height: auto;
    filter: drop-shadow(0 0 15px rgba(0, 242, 255, 0.4));
}

.logo-text-img {
    height: 22px;
    width: auto;
    object-fit: contain;
}

/* Hide original Manual TOC if it appears at the start */
#manual-content > ol:first-of-type,
#manual-content > ul:first-of-type {
    display: none;
}

.nav-links {
    list-style: none;
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    transition: var(--transition);
    line-height: 1.4;
}

.sec-num {
    font-weight: 800;
    font-family: var(--font-heading);
    color: var(--text-muted);
    font-size: 0.75rem;
    min-width: 20px;
}

.nav-links a.active .sec-num {
    color: var(--accent-color);
}

.nav-links li a:hover {
    color: var(--accent-color);
    background: rgba(0, 242, 255, 0.05);
}

.nav-links li a.active {
    color: var(--accent-color);
    background: rgba(0, 242, 255, 0.1);
    font-weight: 600;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: calc(1rem + env(safe-area-inset-top, 0px));
    left: 1rem;
    z-index: 3000; /* Highest to be always accessible */
    background: var(--bg-color);
    color: var(--accent-color);
    border: 1px solid var(--border-color);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: var(--transition);
}

.mobile-branding {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    min-height: 70px;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    z-index: 1500;
    display: none; /* Default hidden, shown in media query */
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    backdrop-filter: var(--glass-blur);
}

/* Main Content */
main.content {
    margin-left: 320px;
    padding: 2.5rem 6%;
    max-width: 1200px;
    transition: var(--transition);
    min-width: 0; /* Prevent flex overflow if used as flex item */
}

#manual-content {
    width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 10000;
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    box-shadow: 0 0 10px var(--accent-color);
}

/* Markdown Rendering Styles */
#manual-content h1 {
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 3rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -2px;
}

#manual-content h2 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

#manual-content h2::before {
    content: '';
    display: block;
    width: 4px;
    height: 24px;
    background: var(--accent-color);
    border-radius: 2px;
}

#manual-content h3 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

#manual-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

#manual-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

#manual-content blockquote {
    background: var(--card-bg);
    border-left: 4px solid var(--accent-color);
    padding: 1.5rem 2rem;
    margin: 2rem 0;
    border-radius: 0 12px 12px 0;
    font-style: italic;
}

#manual-content .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.5rem 0;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 100%;
}
#manual-content table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
}

@media (max-width: 768px) {
    #manual-content td, #manual-content th {
        padding: 0.75rem;
        font-size: 0.85rem;
        word-break: break-word;
    }
    
    #manual-content td:first-child, 
    #manual-content th:first-child {
        min-width: 90px;
        font-weight: 600;
        background: rgba(255, 255, 255, 0.02);
    }

    #manual-content td:nth-child(2), 
    #manual-content th:nth-child(2) {
        min-width: 80px;
    }
}

#manual-content th {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#manual-content td {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.95rem;
}

#manual-content a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 242, 255, 0.2);
    padding-bottom: 1px;
    transition: var(--transition);
}

#manual-content a:hover {
    border-bottom-color: var(--accent-color);
    background: rgba(212, 255, 0, 0.05);
}

#manual-content ul {
    list-style: none;
    margin-left: 0;
}

#manual-content li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.8rem;
    color: var(--text-secondary);
}

#manual-content li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    width: 6px;
    height: 6px;
    background: var(--accent-color);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-color);
}

#manual-content ol {
    padding-left: 1.5rem;
}

#manual-content ol li::before {
    display: none;
}

/* Glass Cards for Sections */
.section-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    backdrop-filter: var(--glass-blur);
    padding: 2rem 2.5rem;
    border-radius: 24px;
    margin-bottom: 4rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.section-card h2:first-child {
    margin-top: 0;
}

.section-card:hover {
    border-color: rgba(0, 242, 255, 0.2);
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

/* Floating Actions */
.floating-actions {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 500;
}

.btn-float {
    width: 50px;
    height: 50px;
    border-radius: 25px;
    background: var(--sidebar-bg);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    transition: var(--transition);
}

/* Custom Quotes */
.custom-quote {
    display: flex;
    gap: 1.2rem;
    background: rgba(255, 255, 255, 0.03);
    border-left: 2px solid var(--accent-color);
    padding: 1.5rem;
    border-radius: 8px;
    margin: 2rem 0;
    align-items: flex-start;
}

.custom-quote i {
    flex-shrink: 0;
    color: var(--accent-color);
    width: 20px;
    margin-top: 2px;
}

.custom-quote.tip { border-left-color: #00d1ff; }
.custom-quote.tip i { color: #00d1ff; }
.custom-quote.warning { border-left-color: #ffaa00; background: rgba(255, 170, 0, 0.05); }
.custom-quote.warning i { color: #ffaa00; }
.custom-quote.important { border-left-color: var(--accent-color); background: rgba(212, 255, 0, 0.05); }

.quote-content {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
    z-index: 5000;
    display: none; /* Controlled by JS */
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.search-modal {
    width: 100%;
    max-width: 600px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 40px 100px rgba(0,0,0,0.5);
}

.search-input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: #fff;
    font-size: 1.2rem;
    padding: 1rem 1.5rem;
    outline: none;
    margin-bottom: 1.5rem;
    font-family: var(--font-body);
}

.search-input:focus {
    border-color: var(--accent-color);
}

.search-results {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.search-item {
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 0.5rem;
    border: 1px solid transparent;
}

.search-item:hover {
    background: rgba(0, 242, 255, 0.05);
    border-color: rgba(0, 242, 255, 0.1);
}

.search-item h4 {
    color: var(--accent-color);
    margin-bottom: 0.25rem;
}

.search-item p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}

/* Responsive Design */
@media (max-width: 1024px) {
    html {
        scroll-padding-top: calc(110px + env(safe-area-inset-top, 0px)) !important;
        scroll-behavior: smooth;
    }

    aside.sidebar {
        transform: translateX(-100%);
        width: 300px;
        z-index: 2500; /* Above branding bar (1500) */
        padding-top: calc(5.5rem + env(safe-area-inset-top, 0px)); /* Clear the toggle button */
    }
    
    aside.sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 60px rgba(0,0,0,0.8);
    }

    main.content {
        margin-left: 0;
        padding-top: calc(100px + env(safe-area-inset-top, 0px));
        padding-left: 5%;
        padding-right: 5%;
        padding-bottom: 3rem;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .mobile-branding {
        display: flex;
    }

    .mobile-branding .logo-icon {
        width: 44px;
        height: 44px;
    }

    .mobile-branding img {
        height: 20px;
    }

    #manual-content h1, 
    #manual-content h2, 
    #manual-content h3 {
        scroll-margin-top: calc(120px + env(safe-area-inset-top, 0px));
    }

    #manual-content h1 {
        font-size: 2.5rem;
        margin-bottom: 2rem;
    }

    .section-card {
        padding: 1rem;
        border-radius: 20px;
    }

    #manual-content h2 {
        scroll-margin-top: calc(100px + env(safe-area-inset-top, 0px));
    }


}

@media (max-width: 768px) {
    html {
        scroll-padding-top: calc(110px + env(safe-area-inset-top, 0px)) !important;
    }

    #manual-content h1,
    #manual-content h2,
    #manual-content h3 {
        scroll-margin-top: calc(120px + env(safe-area-inset-top, 0px));
    }

    #manual-content h1 {
        font-size: 2rem;
    }

    #manual-content h2 {
        font-size: 1.4rem;
    }

    #manual-content p {
        font-size: 1rem;
    }

    .section-card {
        padding: 1.5rem;
        border-radius: 16px;
    }

    .btn-float {
        width: 44px;
        height: 44px;
    }
    
    .floating-actions {
        bottom: 1rem;
        right: 1rem;
    }

    main.content {
        padding-top: calc(90px + env(safe-area-inset-top, 0px));
        padding-left: 4%;
        padding-right: 4%;
        padding-bottom: 2rem;
    }
}

@media (max-width: 480px) {
    #manual-content h1 {
        font-size: 1.8rem;
    }
    
    .logo-text {
        font-size: 1.2rem;
    }
}
