/* === Variables === */
:root {
    --font-sans: 'Source Sans 3', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, 'Courier New', monospace;

    --text-primary: #1a1a1a;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-link: #2563eb;
    --text-link-hover: #1d4ed8;

    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-light: #edf2f7;

    --code-bg: #f1f5f9;
    --code-text: #334155;
    --pre-bg: #f8f9fb;
    --pre-text: #3b4252;

    --accent: #6366f1;
    --accent-light: rgba(99, 102, 241, 0.08);

    --radius: 0.5rem;
    --radius-sm: 0.375rem;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* === Layout === */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

main { flex: 1; }

footer {
    border-top: 1px solid var(--border);
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* === Breadcrumbs === */
.breadcrumbs {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.125rem;
    min-width: 0;
    overflow: hidden;
}
.breadcrumbs a {
    color: var(--text-link);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .sep { color: var(--text-muted); margin: 0 0.25rem; flex-shrink: 0; }
.breadcrumbs span:last-child { color: var(--text-primary); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === Landing Page === */
.landing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 2rem;
}
.landing-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    max-width: 480px;
    text-align: center;
}
.ascii-art {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.45;
    background: #1e293b;
    color: #8892b0;
    padding: 0;
    margin: 0 0 1.5rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
    white-space: pre;
    text-align: left;
}
.aa-dots { color: #ff5f57; }
.aa-title { color: #e2e8f0; font-weight: 600; }
.aa-prompt { color: #64ffda; font-weight: 700; }
.aa-cmd { color: #82aaff; font-weight: 600; }
.aa-file { color: #c3e88d; }
.aa-dir { color: #82aaff; font-weight: 500; }
.aa-img { color: #c792ea; }
.aa-bar { color: #64ffda; letter-spacing: -0.05em; }
.aa-ok { color: #c3e88d; font-weight: 600; }
.aa-url { color: #ffcb6b; }
.hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.6; }
.hint a { color: var(--accent); text-decoration: none; }

/* === 404 === */
.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 2rem;
    text-align: center;
}
.error-page h1 { font-size: 4rem; font-weight: 700; color: var(--text-muted); }
.error-page p { color: var(--text-secondary); margin: 1rem 0; }
.error-page a { color: var(--accent); text-decoration: none; }

/* === Directory Listing === */
.directory {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}
.directory h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}
.file-list {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    table-layout: fixed;
}
.file-list td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    vertical-align: middle;
    white-space: nowrap;
}
.file-list tr:last-child td { border-bottom: none; }
.file-list tr:hover { background: var(--accent-light); }
.file-list .icon { width: 2rem; text-align: center; padding-right: 0; }
.file-list td:nth-child(2) { overflow: hidden; text-overflow: ellipsis; }
.file-list .size {
    width: 5.5rem;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    padding-left: 0.5rem;
}
.file-list a {
    color: var(--text-link);
    text-decoration: none;
    font-weight: 500;
}
.file-list a:hover { text-decoration: underline; color: var(--text-link-hover); }

/* === Markdown Layout (sidebar + content) === */
.md-layout {
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.85rem;
    overflow-y: auto;
    position: sticky;
    top: 49px;
    max-height: calc(100vh - 49px);
}
.sidebar .parent-link {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 1rem;
    font-size: 0.8rem;
}
.sidebar .parent-link:hover { color: var(--text-link); }
.sidebar ul { list-style: none; }
.sidebar li { margin-bottom: 0.25rem; }
.sidebar li a {
    display: block;
    padding: 0.3rem 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar li a:hover { background: var(--accent-light); color: var(--text-link); }
.sidebar li.active a {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.md-layout main {
    flex: 1;
    min-width: 0;
    padding: 2rem 2.5rem;
    background: var(--surface);
}

/* === Markdown Content Typography === */
.md-content {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.7;
    color: var(--text-primary);
    word-spacing: 0.02em;
    overflow-wrap: break-word;
}

.md-content h1, .md-content h2, .md-content h3,
.md-content h4, .md-content h5, .md-content h6 {
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    scroll-margin-top: 4rem;
}
.md-content h1 { font-size: 2rem; margin-top: 0; padding-bottom: 0.5rem; border-bottom: 2px solid var(--border); }
.md-content h2 { font-size: 1.625rem; margin-top: 2.5rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }
.md-content h3 { font-size: 1.375rem; margin-top: 2rem; }
.md-content h4 { font-size: 1.15rem; }
.md-content h5 { font-size: 1rem; font-weight: 600; }
.md-content h6 { font-size: 0.875rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

.md-content p { margin-bottom: 1.25rem; }

.md-content a { color: var(--text-link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; transition: color 0.15s; }
.md-content a:hover { color: var(--text-link-hover); text-decoration-thickness: 2px; }

.md-content strong { font-weight: 700; }
.md-content em { font-style: italic; }
.md-content mark { background: #fef3c7; padding: 0.1em 0.25em; border-radius: 0.2em; }

/* Lists */
.md-content ul, .md-content ol { margin-bottom: 1.25rem; padding-left: 1.75rem; }
.md-content li { margin-bottom: 0.35rem; }
.md-content li > p { margin-bottom: 0.35rem; }
.md-content ul > li { list-style-type: disc; }
.md-content ul ul > li { list-style-type: circle; }
.md-content ol { list-style-type: decimal; }
.md-content ol ol { list-style-type: lower-alpha; }
.md-content input[type="checkbox"] { margin-right: 0.5rem; }

/* Code */
.md-content code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--code-bg);
    color: var(--code-text);
    padding: 0.15em 0.35em;
    border-radius: 0.25em;
    border: 1px solid var(--border);
    font-weight: 500;
}
.md-content pre {
    background: var(--pre-bg);
    color: var(--pre-text);
    padding: 1.25rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 1.25rem 0;
    font-size: 0.875rem;
    line-height: 1.6;
    border: 1px solid var(--border);
}
.md-content pre code {
    background: none;
    color: inherit;
    padding: 0;
    border: none;
    font-size: inherit;
}

/* Blockquotes */
.md-content blockquote {
    margin: 1.5rem 0;
    padding: 0.75rem 1.25rem;
    border-left: 4px solid var(--accent);
    background: var(--accent-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}
.md-content blockquote p { margin-bottom: 0.5rem; }
.md-content blockquote p:last-child { margin-bottom: 0; }

/* Tables */
.md-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.875rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.md-content thead { background: var(--code-bg); }
.md-content th {
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.md-content td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}
.md-content tbody tr:hover { background: var(--accent-light); }

/* Horizontal Rules */
.md-content hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 2.5rem 0;
}

/* Images */
.md-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    margin: 1rem 0;
}

/* Mermaid */
.md-content .mermaid {
    text-align: center;
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Keyboard */
.md-content kbd {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 0.25rem;
    box-shadow: 0 1px 0 #cbd5e1;
    font-family: inherit;
    font-size: 0.85em;
    padding: 0.1em 0.35em;
}

/* === Source Code Viewer === */
.source-view { font-family: var(--font-mono); }
.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.85rem;
}
.source-filename { font-weight: 600; color: var(--text-primary); }
.source-lang { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.source-view pre {
    margin: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    border: 1px solid var(--border);
    background: var(--pre-bg);
    overflow-x: auto;
}
.source-view pre code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.6;
    display: block;
    padding: 1.25rem;
    tab-size: 4;
}

/* === Dark Mode === */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #e2e8f0;
        --text-secondary: #a0aec0;
        --text-muted: #718096;
        --text-link: #60a5fa;
        --text-link-hover: #93c5fd;
        --bg: #0f172a;
        --surface: #1e293b;
        --border: #334155;
        --border-light: #2d3748;
        --code-bg: #1e293b;
        --code-text: #e2e8f0;
        --pre-bg: #1a1e2e;
        --pre-text: #d8dee9;
        --accent-light: rgba(99, 102, 241, 0.15);
    }
    .md-content mark { background: #fbbf24; color: #1f2937; }
    .hljs { background: var(--pre-bg) !important; color: var(--pre-text) !important; }
    .hljs-keyword, .hljs-selector-tag, .hljs-type { color: #81a1c1 !important; }
    .hljs-string, .hljs-attr { color: #a3be8c !important; }
    .hljs-number, .hljs-literal { color: #b48ead !important; }
    .hljs-comment { color: #616e88 !important; }
    .hljs-built_in, .hljs-title { color: #88c0d0 !important; }
    .hljs-variable, .hljs-template-variable { color: #d08770 !important; }
}

/* === Responsive === */
@media (max-width: 768px) {
    header { padding: 0.5rem 1rem; }
    .breadcrumbs { font-size: 0.8rem; gap: 0; }
    .breadcrumbs a { max-width: 140px; }
    .breadcrumbs .sep { margin: 0 0.15rem; }

    .md-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 0.75rem 1rem;
    }
    .sidebar ul { display: flex; flex-wrap: wrap; gap: 0.25rem; }
    .sidebar li { margin-bottom: 0; }
    .sidebar li a { font-size: 0.8rem; padding: 0.25rem 0.5rem; }
    .md-layout main { padding: 1.25rem 1rem; }

    .md-content h1 { font-size: 1.5rem; }
    .md-content h2 { font-size: 1.25rem; }
    .md-content h3 { font-size: 1.1rem; }
    .md-content table { font-size: 0.8rem; }
    .md-content th, .md-content td { padding: 0.5rem; }
    .md-content pre { padding: 0.75rem; font-size: 0.8rem; }
    .md-content blockquote { margin: 1rem 0; padding: 0.5rem 1rem; }

    .directory { padding: 0 0.75rem; margin: 1rem auto; }
    .directory h1 { font-size: 1.25rem; margin-bottom: 1rem; }
    .file-list td { padding: 0.5rem 0.5rem; font-size: 0.85rem; }
    .file-list .icon { width: 1.75rem; }
    .file-list .size { width: 4.5rem; font-size: 0.75rem; }

    .landing { padding: 1rem; }
    .landing-card { padding: 1.25rem; max-width: 100%; }
    .ascii-art { font-size: 0.6rem; line-height: 1.35; }

    .source-header { padding: 0.5rem 0.75rem; }
    .source-view pre code { padding: 0.75rem; font-size: 0.8rem; }
}

@media (max-width: 480px) {
    header { padding: 0.4rem 0.75rem; }
    .breadcrumbs { font-size: 0.75rem; }
    .breadcrumbs a { max-width: 100px; }
    .md-layout main { padding: 1rem 0.75rem; }
    .md-content h1 { font-size: 1.3rem; }
    .md-content { font-size: 0.925rem; }
    .md-content ul, .md-content ol { padding-left: 1.25rem; }

    .file-list td { padding: 0.4rem 0.35rem; font-size: 0.8rem; }
    .file-list .size { width: 4rem; font-size: 0.7rem; }

    .ascii-art { font-size: 0.5rem; }
}
