/* ===== Design Tokens (来源: JAcoworks) ===== */
:root {
    /* ===== Colors — 暖色奶油基调 ===== */
    --bg-primary: #F5F0EB;
    --bg-secondary: #FAF7F4;
    --bg-tertiary: #EDE8E3;
    --bg-input: #FFFFFF;
    --bg-hover: #EDE8E3;
    --bg-active: #E5E0DA;
    --bg-card: #FFFFFF;
    --bg-code: #1a1a2e;

    /* 文字 */
    --text-primary: #1A1A1A;
    --text-secondary: #5A5248;
    --text-muted: #8B7E74;
    --text-on-accent: #FFFFFF;

    /* 强调色 - 暖色珊瑚/陶土色 */
    --accent: #C4724A;
    --accent-hover: #B06540;
    --accent-light: rgba(196, 114, 74, 0.1);

    --danger: #D94040;

    /* 边框 */
    --border: #E0D8D0;
    --border-light: rgba(0, 0, 0, 0.06);

    /* 滚动条 */
    --scrollbar-thumb: #C8C0B8;
    --scrollbar-thumb-hover: #B0A89F;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.06);

    /* ===== Typography ===== */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI',
        'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

    /* ===== Border Radius ===== */
    --radius-sm: 4px;
    --radius: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* ===== Transitions ===== */
    --duration-fast: 0.12s;
    --duration-normal: 0.15s;
    --duration-slow: 0.2s;
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

/* ===== Base Reset ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* ===== Links ===== */
a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-standard);
}

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

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 40;
    transition: transform var(--duration-slow) var(--ease-standard);
    flex-shrink: 0;
}

.sidebar-hidden {
    transform: translateX(-100%);
}

@media (min-width: 1024px) {
    .sidebar {
        position: sticky;
        transform: translateX(0) !important;
    }
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.sidebar-logo-icon {
    font-size: 24px;
}

.sidebar-logo-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.sidebar-logo-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.sidebar-nav {
    padding: 12px;
}

/* Tree navigation */
.tree-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tree-list .tree-list {
    padding-left: 12px;
}

.tree-folder-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-standard);
}

.tree-folder-btn:hover {
    background: var(--bg-hover);
}

.tree-arrow {
    display: inline-block;
    transition: transform var(--duration-fast) var(--ease-standard);
    font-size: 10px;
}

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

.tree-file-link {
    display: block;
    padding: 6px 8px;
    font-size: 13px;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all var(--duration-fast) var(--ease-standard);
}

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

/* Overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 26, 0.28);
    z-index: 30;
}

/* Mobile menu button */
.mobile-menu-btn {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    padding: 8px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: block;
}

@media (min-width: 1024px) {
    .mobile-menu-btn {
        display: none;
    }
    .sidebar-overlay {
        display: none !important;
    }
}

/* Main content */
.main-content {
    flex: 1;
    min-width: 0;
}

.content-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 16px;
    padding-top: 56px;
}

@media (min-width: 640px) {
    .content-container {
        padding-left: 24px;
        padding-right: 24px;
    }
}

@media (min-width: 1024px) {
    .content-container {
        padding-top: 32px;
        padding-left: 32px;
        padding-right: 32px;
    }
}

/* ===== Home Page Cards ===== */
.home-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.home-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 640px) {
    .card-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.doc-card {
    display: block;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: box-shadow var(--duration-normal) var(--ease-standard),
                border-color var(--duration-normal) var(--ease-standard);
}

.doc-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-light);
}

.doc-card-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.doc-card-title {
    font-weight: 600;
    color: var(--text-primary);
}

.doc-card-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===== TOC ===== */
.toc-container {
    margin-bottom: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
}

.toc-summary {
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.toc-nav {
    margin-top: 12px;
}

.toc-link {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 2px 0;
    transition: color var(--duration-fast);
}

.toc-link:hover {
    color: var(--accent);
}

.toc-indent-1 { padding-left: 0; }
.toc-indent-2 { padding-left: 16px; }
.toc-indent-3 { padding-left: 32px; }

/* ===== Prose / Markdown Content ===== */
.prose h1, .prose h2, .prose h3,
.prose h4, .prose h5, .prose h6 {
    color: var(--text-primary);
    line-height: 1.3;
    scroll-margin-top: 64px;
}

.prose h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

.prose h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border-light);
}

.prose h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
}

.prose h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.prose p {
    margin-bottom: 1rem;
    line-height: 1.75;
    color: var(--text-secondary);
}

.prose ul, .prose ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.prose li {
    margin-bottom: 0.375rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.prose a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(196, 114, 74, 0.25);
    text-underline-offset: 2px;
    transition: text-decoration-color var(--duration-fast);
}

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

.prose blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-style: italic;
}

.prose hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.prose strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Tables */
.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.875rem;
}

.prose th {
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.625rem 0.75rem;
    border-bottom: 2px solid var(--border);
    background: var(--bg-tertiary);
}

.prose td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.prose tr:hover td {
    background: var(--bg-hover);
}

.overflow-x-auto {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Code */
.prose code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-tertiary);
    padding: 0.15em 0.4em;
    border-radius: var(--radius-sm);
    color: var(--accent);
}

.prose pre {
    background: var(--bg-code);
    color: #e2e8f0;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    overflow-x: auto;
    margin: 1.5rem 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.prose pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

/* Images */
.prose img {
    max-width: 100%;
    border-radius: var(--radius-lg);
    margin: 1.5rem 0;
    box-shadow: var(--shadow-sm);
}

/* Video */
.prose video {
    max-width: 100%;
    border-radius: var(--radius-lg);
}

/* ===== Loading skeleton ===== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Error page ===== */
.error-page {
    text-align: center;
    padding: 64px 16px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-text {
    color: var(--text-muted);
}

.error-link {
    color: var(--accent);
    margin-top: 16px;
    display: inline-block;
}

.error-link:hover {
    text-decoration: underline;
}

/* ===== Icon Utilities ===== */
.icon-accent {
    color: var(--accent);
}

.icon-muted {
    color: var(--text-muted);
}

.icon-inline {
    display: inline-block;
    vertical-align: -3px;
    margin-right: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .prose {
        font-size: 0.95rem;
    }

    .prose table {
        font-size: 0.8rem;
    }

    .prose pre {
        border-radius: 0;
        margin-left: -16px;
        margin-right: -16px;
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ===== Image Lightbox ===== */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    animation: fadeIn var(--duration-slow) var(--ease-standard);
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full, 9999px);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background var(--duration-fast);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== Video Player ===== */
.video-container {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #000;
    margin: 1.5rem 0;
}

.video-container video {
    width: 100%;
    display: block;
}

/* ===== Mermaid Diagrams ===== */
.mermaid-container {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    text-align: center;
}

.mermaid-container svg {
    max-width: 100%;
    height: auto;
}

/* ===== ASCII Art / Diagram blocks ===== */
.prose pre code {
    font-family: var(--font-mono);
    white-space: pre;
    tab-size: 4;
}
