/* ============================================
   Mizushi — Knowledge Base Styles
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Light theme */
    --bg: #ffffff;
    --bg-subtle: #f8f9fa;
    --bg-card: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --text-heading: #111827;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: #eff6ff;
    --tag-bg: #f3f4f6;
    --tag-text: #4b5563;
    --tag-hover-bg: #e5e7eb;
    --code-bg: #f3f4f6;
    --code-text: #1f2937;
    --blockquote-border: #2563eb;
    --blockquote-bg: #f8faff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --max-width: 1200px;
    --sidebar-width: 240px;
    --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --bg-subtle: #111111;
        --bg-card: #111111;
        --text: #e2e8f0;
        --text-muted: #94a3b8;
        --text-heading: #f1f5f9;
        --border: #222222;
        --accent: #60a5fa;
        --accent-hover: #93bbfd;
        --accent-bg: #0a1628;
        --tag-bg: #1a1a1a;
        --tag-text: #cbd5e1;
        --tag-hover-bg: #2a2a2a;
        --code-bg: #111111;
        --code-text: #e2e8f0;
        --blockquote-border: #60a5fa;
        --blockquote-bg: #0a0a0a;
        --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
        --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3);
        --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3);
    }
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

/* --- Header --- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.nav {
    max-width: var(--max-width);
    margin: 0 auto;
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 20px;
}

.nav-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

.nav-logo:hover {
    color: var(--accent);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 16px;
}

.nav-link {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.nav-link:hover {
    color: var(--text);
    text-decoration: none;
}

.nav-search {
    margin-left: auto;
}

#search-input {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    color: var(--text);
    font-size: 0.8rem;
    width: 180px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

/* --- Layout (sidebar + content) --- */
.layout {
    max-width: var(--max-width);
    margin: 0 auto;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: calc(100vh - var(--header-height) - 60px);
}

@media (max-width: 860px) {
    .layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        display: none;
    }
    .content {
        grid-column: 1;
    }
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: max(calc((100vw - var(--max-width)) / 2), 0px);
    width: var(--sidebar-width);
    padding: 32px 16px 32px 0;
    max-height: calc(100vh - var(--header-height));
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    z-index: 10;
}

.sidebar::-webkit-scrollbar {
    display: none;
}

.sidebar-section h3 {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding-left: 4px;
}

/* Folder navigation */
.folder-nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.folder-group {
    display: flex;
    flex-direction: column;
}

.folder-group.depth-2 {
    padding-left: 12px;
}

.folder-group.depth-3 {
    padding-left: 24px;
}

.folder-group.depth-4,
.folder-group.depth-5,
.folder-group.depth-6 {
    padding-left: 36px;
}

.folder-header-root {
    /* invisible spacer for root articles */
    display: none;
}

.folder-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-heading);
    padding: 2px 8px;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.folder-articles {
    list-style: none;
    padding: 0;
    margin: 0;
}

.folder-articles li {
    margin: 0;
}

.folder-link {
    display: block;
    padding: 4px 8px 4px 12px;
    font-size: 0.8rem;
    color: var(--text);
    border-radius: var(--radius-sm);
    transition: background 0.1s;
    border-left: 2px solid transparent;
}

.folder-link:hover {
    background: var(--tag-bg);
    text-decoration: none;
    border-left-color: var(--accent);
}

/* --- Main Content --- */
.content {
    grid-column: 2;
    padding: 40px 32px;
    min-width: 0;
}

/* --- Article List --- */
.article-list h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 28px;
    color: var(--text-heading);
}

.article-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.article-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    transition: box-shadow 0.2s, transform 0.15s;
}

.article-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.article-card h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.article-card h2 a {
    color: var(--text-heading);
}

.article-card h2 a:hover {
    color: var(--accent);
    text-decoration: none;
}

.card-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.article-excerpt {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.6;
    margin-bottom: 10px;
    overflow: hidden;
}

.article-excerpt p {
    margin: 0;
}

.article-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- Tags --- */
.article-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--tag-text);
    background: var(--tag-bg);
    border-radius: 999px;
    transition: background 0.15s;
}

.tag-badge:hover {
    background: var(--tag-hover-bg);
    text-decoration: none;
    color: var(--tag-text);
}

.tag-badge-large {
    font-size: 0.85rem;
    padding: 3px 10px;
}

/* --- Single Article --- */
.single-article {
    max-width: 720px;
}

.article-header {
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.article-header h1 {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.3;
    color: var(--text-heading);
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.article-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.article-body {
    font-size: 0.95rem;
    line-height: 1.8;
}

.article-body h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-top: 36px;
    margin-bottom: 14px;
    color: var(--text-heading);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.article-body h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 28px;
    margin-bottom: 10px;
    color: var(--text-heading);
}

.article-body h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 20px;
    margin-bottom: 8px;
    color: var(--text-heading);
}

.article-body p {
    margin-bottom: 14px;
}

.article-body ul, .article-body ol {
    margin-bottom: 14px;
    padding-left: 22px;
}

.article-body li {
    margin-bottom: 4px;
}

.article-body blockquote {
    border-left: 4px solid var(--blockquote-border);
    background: var(--blockquote-bg);
    padding: 14px 18px;
    margin: 14px 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-muted);
}

.article-body blockquote p:last-child {
    margin-bottom: 0;
}

.article-body code {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

.article-body pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin: 14px 0;
    overflow-x: auto;
}

.article-body pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
}

.article-body th, .article-body td {
    padding: 8px 14px;
    border: 1px solid var(--border);
    text-align: left;
}

.article-body th {
    background: var(--bg-subtle);
    font-weight: 600;
}

.article-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 28px 0;
}

/* --- Footnotes as Side Notes --- */
.footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 1;
}

.footnote-ref a {
    color: var(--accent);
    text-decoration: none;
}

.footnote-ref a:hover {
    text-decoration: underline;
}

/* Footnotes float to the right of the article content area on wide screens */
.footnote-side {
    margin: 8px 0;
    padding: 8px 12px 6px;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.fn-marker {
    font-weight: 600;
    color: var(--accent);
    margin-right: 4px;
}

/* On wider screens, float footnotes to the right of the article */
@media (min-width: 1201px) {
    .footnote-side {
        float: right;
        clear: right;
        width: 200px;
        margin: 4px 0 8px;
        margin-right: -200px;
    }
}

/* --- Article Navigation --- */
.article-nav {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.back-link:hover {
    color: var(--accent);
    text-decoration: none;
}

/* --- Search Overlay --- */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 200;
    display: flex;
    justify-content: center;
    padding-top: 120px;
    backdrop-filter: blur(8px);
}

.search-overlay.hidden {
    display: none;
}

.search-overlay-content {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 600px;
    max-width: 90vw;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-overlay-header {
    display: flex;
    align-items: center;
    padding: 14px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

#search-overlay-input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
}

#search-overlay-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

#search-overlay-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    line-height: 1;
}

#search-overlay-close:hover {
    background: var(--tag-bg);
    color: var(--text);
}

.search-results {
    overflow-y: auto;
    padding: 8px 0;
}

.search-results .result-item {
    display: block;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

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

.search-results .result-item:hover {
    background: var(--accent-bg);
    text-decoration: none;
}

.search-results .result-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 2px;
}

.search-results .result-empty {
    padding: 28px;
    text-align: center;
    color: var(--text-muted);
}

/* --- Empty State --- */
.empty-state {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 14px 0;
}

/* --- Footer --- */
.site-footer {
    text-align: center;
    padding: 20px;
    font-size: 0.7rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* --- KaTeX fixes --- */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 0;
}
