@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Rajdhani:wght@300;400;500;600&family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;1,300&display=swap');

:root {
    --bg-base: #0e0f11;
    --bg-surface: #14161a;
    --bg-raised: #1a1d23;
    --bg-hover: #1f2229;
    --border: #2a2d35;
    --border-accent: #3a3f4e;
    --accent: #4af3c8;
    --accent-active: #ffd300;
    --accent-dim: #1f7a66;
    --accent-glow: rgba(74, 243, 200, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #b6b8be;
    --text-muted: #555a6a;
    --font-display: 'Rajdhani', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-ui: 'Share Tech Mono', monospace;
    --sidebar-w: 20vw;
    --header-h: 52px;
}

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

html,
body {
    height: 100%;
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 16px;
    line-height: 1.7;
    overflow: hidden;
}

/* ── Scanline overlay ── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.05) 2px,
            rgba(0, 0, 0, 0.05) 4px);
    pointer-events: none;
    z-index: 1000;
}

/* ── Layout shell ── */
#app {
    display: grid;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
}

/* ── Header ── */
#header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

#footer {
    grid-column: 1 / -1;
    justify-content: flex-end;
    align-items: center;
    display: flex;
    padding: 0 1.5rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

#header .logo {
    font-family: var(--font-ui);
    font-size: 18px;
    color: var(--accent);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 10px;
}

#header .logo::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

#header .breadcrumb,
#footer .breadcrumb {
    margin-left: 1.0rem;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

#footer .breadcrumb.breadcrumb-nooverflow {
    max-width: 10%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#author-link {
    color: var(--accent-active);
}

#header .breadcrumb .sep {
    color: var(--accent-dim);
}

#header .breadcrumb .current {
    color: var(--text-secondary);
}

#header .status {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}



/* 
    Sidebar section.
*/

#sidebar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    transform: translateX(0);           /* visible state */
    transition: transform 0.3s ease;    /* MUST be here */
    width: var(--sidebar-w);
    z-index: 1;
}

body.sidebar-closed {
    --sidebar-w: 0px;
}

#sidebar.closed {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

/* Floating button */
#sidebar-button {
    position: fixed;
    bottom: 32px;
    right: 10px;

    z-index: 2000;

    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;

    color: white;
}

#sidebar-button:hover {
    background-color: var(--accent-active);
    transition: transform 0.2s ease, background-color 0.2s ease;
    color: var(--bg-base);
}
#sidebar::-webkit-scrollbar {
    width: 3px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 2px;
}

.sidebar-section-label {
    font-family: var(--font-ui);
    font-size: 10px;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    padding: 1.2rem 1.2rem 0.5rem;
    text-transform: uppercase;
}

/* Tree nodes */
.tree-root {
    padding: 0 0 1rem;
}

.tree-folder {
    user-select: none;
}

.tree-folder-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 1rem 6px 1.2rem;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.tree-folder-header:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-folder-header .arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.tree-folder-header .arrow svg {
    width: 10px;
    height: 10px;
}

.tree-folder.open>.tree-folder-header .arrow {
    transform: rotate(90deg);
}

.tree-folder-header .folder-icon {
    color: var(--accent-dim);
    font-size: 12px;
    flex-shrink: 0;
}

.tree-folder-header .folder-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-children {
    display: none;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
    margin-left: 1.7rem;
}

.tree-folder.open>.tree-children {
    display: block;
}

.tree-file {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 1rem 5px 0.6rem;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    border-radius: 3px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    border-radius: 20px;
}

.tree-file:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-file.active {
    background: var(--accent-active);
    color: var(--bg-base);
    border-left: 2px solid var(--bg-base);
    margin-left: -2px;
    
}

.tree-file .file-icon {
    color: var(--text-muted);
    font-size: 11px;
    flex-shrink: 0;
}

.tree-file.active .file-icon {
    color: var(--accent);
}

/* ── Main content ── */
#main {
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    background:
        linear-gradient(
            to bottom,
            #222 0%,
            #000 75%,
            #000 100%
        );
}

#main::-webkit-scrollbar {
    width: 4px;
}

#main::-webkit-scrollbar-track {
    background: transparent;
}

#main::-webkit-scrollbar-thumb {
    background: var(--border-accent);
    border-radius: 2px;
}

#content {
    max-width: 90vw;
    margin: 0 auto;
    padding: 3rem 1.5rem 5rem;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex-direction: column;
    gap: 1rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 13px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 1.5px solid var(--border-accent);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#error-state {
    display: none;
    max-width: 540px;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.8;
}

#error-state h3 {
    color: #f07070;
    font-size: 14px;
    margin-bottom: 0.8rem;
    font-family: var(--font-ui);
    letter-spacing: 0.1em;
}

#error-state p {
    color: var(--text-secondary);
}

#error-state code {
    color: var(--accent);
    background: var(--bg-raised);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.content-area {
    position: relative;
    z-index: 1;
}

.tab-header {
    width: 30%;

    white-space: nowrap;      /* Prevent line wrapping */
    overflow: hidden;         /* Hide overflow */
    text-overflow: ellipsis;  /* Show ... */

    background: var(--accent);
    padding: 0.4rem 1.2rem;
    color: var(--bg-base);
    font-weight: bold;
    
    border: 2px solid var(--accent);
}

/* Corner decoration on content area */
#content::before {
    content: '';
    position: fixed;
    top: var(--header-h);
    right: 0;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle at top right, rgba(74, 243, 200, 0.04), transparent 70%);
    pointer-events: none;
}

/* 
    Markdown content styles
*/

.md-body {
    padding: 5%;
    border: 1px solid var(--accent);
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4,
.md-body h5,
.md-body h6 {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    margin: 2rem 0 0.8rem;
}

.md-body h1 {
    font-size: 2.6rem;
    color: var(--accent);
    letter-spacing: 0.02em;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    margin-top: 0;
}

.md-body h2 {
    font-size: 2.2rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.md-body h3 {
    font-size: 1.8rem;
    color: var(--text-secondary);
}

.md-body h4 {
    font-size: 1.6rem;
    color: var(--text-muted);
}

.md-body p {
    margin: 0 0 1.2rem;
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 400;
    line-height: 1.85;
}

.md-body a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-dim);
    transition: border-color 0.15s;
}

.md-body a:hover {
    border-color: var(--accent);
}

.md-body ul,
.md-body ol {
    margin: 0 0 1.2rem 1.5rem;
    color: var(--text-primary);
    font-weight: 400;
    font-size: 1.2rem;
}

.md-body li {
    margin: 0.3rem 0;
}

.md-body blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    border-left: 3px solid var(--accent);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-style: italic;
    border-radius: 0 4px 4px 0;
}

.md-body blockquote p {
    margin: 0;
    color: inherit;
}

.md-body .code-block {
    overflow: hidden;
}

.md-body .code-header {
    display: flex;
    background-color: var(--border);
    justify-content: flex-end;
    border-radius: 5px 5px 0px 0px;
    margin-bottom: 0px;
    padding: 16px 16px;
}

.md-body .code-header button {
    font-family: var(--font-display);
    font-size: 16px;
    background-color: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
}

.md-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-raised);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid var(--border);
}

.md-body pre {
    margin: 1.5rem 0;
    margin-top: 0;
    border-radius: 0px 0px 6px 6px;
    border: 1px solid var(--border);
    border-top: none;
    overflow: hidden;
    position: relative;
}

.md-body pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border: none;
    border-radius: 0;
    font-size: 1.1rem;
    display: block;
}

.md-body pre .hljs {
    padding: 1.2rem 1.5rem;
    background: #0d1117;
    border-radius: 5px;
    overflow-x: auto;
}

.code-label {
    position: absolute;
    top: 0;
    right: 0;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--text-muted);
    background: var(--bg-raised);
    padding: 3px 10px;
    border-bottom-left-radius: 5px;
    border: 1px solid var(--border);
    letter-spacing: 0.05em;
}

.md-body .table-container {
  overflow-x: auto;
  width: 100%;
}

.md-body .table-container table {
  border-collapse: collapse;
  min-width: max-content;
}

.md-body .table-container th,
.md-body .table-container td {
  white-space: nowrap;
}

.md-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-family: var(--font-mono);
    font-size: 1.2rem;
}

.md-body th {
    background: var(--bg-surface);
    color: var(--accent);
    font-weight: 600;
    text-align: left;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.md-body td {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.md-body tr:nth-child(even) td {
    background: var(--bg-surface);
}

.md-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2.5rem 0;
}

.md-body img {
    max-width: 100%;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
    margin: 1.5rem auto;
}

/* KaTeX inline */
.md-body .katex {
    font-size: 1.1em;
}

.md-body .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    font-size: 1.1em;
    padding: 0.1rem 0;
}

.md-body::selection {
    background: var(--accent-active);
    color: var(--bg-base);
}

/* 
    Custom extension to markdown: citation tooltips.
*/

.cite-wrapper {
    position: relative;
    display: inline-block;
    white-space: nowrap;
}

.cite-valid {
    color: var(--accent);
    font-size: 0.75em;
    margin-left: 2px;
    cursor: pointer;
}

.cite-tooltip {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    
    background: var(--accent);
    color: var(--bg-base);
    padding: 8px 10px;
    border-radius: 6px;
    
    font-size: 1.0em;
    white-space: nowrap;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;

    
    z-index: 1000;
}

.cite-wrapper:hover .cite-tooltip {
    opacity: 1.0;
}

/* ── Demo banner (shown when no server) ── */
#demo-banner {
    display: none;
    background: rgba(74, 243, 200, 0.07);
    border-bottom: 1px solid var(--accent-dim);
    padding: 0.5rem 1.5rem;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    grid-column: 1 / -1;
}

#demo-banner span {
    color: var(--accent);
}

/* global scrollbar */
::-webkit-scrollbar {
    width: 1px;
    height: 1px; /* horizontal */
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: white;
    border-radius: 1px;
}

.chapter-index {
    color: rgb(128, 128, 128);
    font-family: monospace;
}
/*
    Section for responsive sidebar behavior. 
    On small screens, the sidebar becomes a sliding 
    drawer with a toggle button.
*/
@media (min-width: 701px) {
    #sidebar-button {
        display: none;
    }
}

@media (max-width: 700px) {

    #app {
        grid-template-columns: 1fr; /* remove sidebar column */
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: 0;

        width: 100%;
        height: 100%;

        z-index: 1500;

        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    #sidebar-button {
        bottom: 40px;
    }

    #header .breadcrumb {
        overflow-x: auto;
        white-space: nowrap;
    }

    #sidebar.closed {
        transform: translateX(0);
    }

    #main {
        grid-column: 1 / -1; /* full width */
    }

    #content {
        max-width: 100vw;
        padding: 0;
        margin: 0;
    }

    .md-body {
        border: none;
    }

    .tab-header {
        width: 100%;
    }
}
