/* ═══════════════════════════════════════════
   CSS VARIABLES
   ═══════════════════════════════════════════ */
:root {
    --brand: #1e40af;
    --brand-dark: #1a3590;
    --brand-light: #3b82f6;
    --brand-wash: #eff6ff;
    --brand-ghost: #f5f8ff;

    --ink: #111827;
    --ink-secondary: #4b5563;
    --ink-tertiary: #9ca3af;
    --ink-faint: #d1d5db;

    --surface: #ffffff;
    --surface-raised: #f9fafb;
    --surface-sunken: #f3f4f6;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    --wip-bg: #fef3c7;
    --wip-text: #92400e;
    --wip-border: #fcd34d;

    --sidebar-w: 280px;
    --content-max: 720px;
    --body-size: 19px;
    --body-leading: 1.72;

    --font-body: 'Newsreader', Georgia, 'Times New Roman', serif;
    --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ═══════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════ */
*, *::before, *::after {
    margin: 0; padding: 0; box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-size: var(--body-size);
    line-height: var(--body-leading);
    color: var(--ink);
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════════
   WIP BANNER
   ═══════════════════════════════════════════ */
.wip-banner {
    background: var(--wip-bg);
    border-bottom: 1px solid var(--wip-border);
    padding: 10px 24px;
    text-align: center;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 500;
    color: var(--wip-text);
    position: sticky;
    top: 0;
    z-index: 100;
}

.wip-banner a {
    color: var(--wip-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ═══════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════ */
.page-layout {
    display: flex;
    min-height: 100vh;
}

/* ═══════════════════════════════════════════
   SIDEBAR / TOC
   ═══════════════════════════════════════════ */
.sidebar {
    position: sticky;
    top: 41px; /* wip banner height */
    height: calc(100vh - 41px);
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    border-right: 1px solid var(--border);
    background: var(--surface);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 32px 0 48px;
    scrollbar-width: thin;
    scrollbar-color: var(--ink-faint) transparent;
    z-index: 50;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 2px; }

.sidebar-brand {
    padding: 0 24px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.sidebar-brand-name {
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 15px;
    color: var(--brand);
    letter-spacing: -0.02em;
    text-decoration: none;
    display: block;
}

.sidebar-brand-sub {
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--ink-tertiary);
    margin-top: 2px;
}

.toc-section-label {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-tertiary);
    padding: 16px 24px 6px;
}

.toc-link {
    display: block;
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.4;
    color: var(--ink-secondary);
    text-decoration: none;
    padding: 5px 24px 5px 24px;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
}

.toc-link:hover {
    color: var(--ink);
    background: var(--surface-raised);
}

.toc-link.active {
    color: var(--brand);
    border-left-color: var(--brand);
    background: var(--brand-ghost);
    font-weight: 500;
}

.toc-link.toc-sub {
    padding-left: 36px;
    font-size: 12.5px;
}

.toc-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 24px;
}

/* Mobile TOC toggle */
.toc-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 200;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(30, 64, 175, 0.3);
    transition: transform 0.2s var(--ease-out);
}

.toc-toggle:active { transform: scale(0.95); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 49;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ═══════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════ */
.main-content {
    flex: 1;
    min-width: 0;
    padding: 56px 48px 120px;
    display: flex;
    justify-content: center;
}

.content-column {
    max-width: var(--content-max);
    width: 100%;
}

/* ═══════════════════════════════════════════
   ARTICLE HEADER
   ═══════════════════════════════════════════ */
.article-header {
    margin-bottom: 56px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--border);
}

.article-header h1 {
    font-family: var(--font-body);
    font-size: clamp(32px, 5vw, 44px);
    font-weight: 600;
    line-height: 1.15;
    color: var(--ink);
    letter-spacing: -0.025em;
    margin-bottom: 16px;
}

.article-subtitle {
    font-family: var(--font-body);
    font-size: 20px;
    font-weight: 300;
    color: var(--ink-secondary);
    line-height: 1.5;
    font-style: italic;
    margin-bottom: 28px;
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--ink-secondary);
}

.author-name {
    font-weight: 600;
    color: var(--ink);
}

.author-name a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid var(--ink-faint);
    transition: border-color 0.15s ease;
}

.author-name a:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.meta-dot {
    color: var(--ink-faint);
}

.article-version {
    display: inline-block;
    background: var(--brand-wash);
    color: var(--brand);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

.author-box {
    margin-top: 20px;
    padding: 14px 18px;
    background: var(--brand-wash);
    border: 1px solid rgba(30, 64, 175, 0.15);
    border-radius: 8px;
    font-family: var(--font-ui);
}

.author-box-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-tertiary);
    margin-bottom: 4px;
}

.author-box-text {
    font-size: 14px;
    color: var(--ink-secondary);
    line-height: 1.5;
}

/* ═══════════════════════════════════════════
   TYPOGRAPHY
   ═══════════════════════════════════════════ */
.content-column h2 {
    font-family: var(--font-body);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--ink);
    letter-spacing: -0.015em;
    margin: 64px 0 20px;
    padding-top: 16px;
}

.content-column h3 {
    font-family: var(--font-ui);
    font-size: 20px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--ink);
    margin: 40px 0 12px;
}

.content-column h4 {
    font-family: var(--font-ui);
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    margin: 28px 0 8px;
}

/* Part dividers — large section headings */
.part-heading {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand);
    margin: 80px 0 8px;
    padding-top: 32px;
    border-top: 2px solid var(--brand);
}

.content-column p {
    margin-bottom: 20px;
}

.content-column blockquote {
    border-left: 3px solid var(--brand-light);
    padding: 2px 0 2px 24px;
    margin: 28px 0;
    color: var(--ink-secondary);
    font-style: italic;
}

.content-column blockquote strong {
    font-style: normal;
    color: var(--ink);
}

.content-column a {
    color: var(--brand);
    text-decoration: none;
    border-bottom: 1px solid rgba(30, 64, 175, 0.25);
    transition: border-color 0.15s ease;
}

.content-column a:hover {
    border-color: var(--brand);
}

.content-column code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--surface-sunken);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--ink);
}

.content-column pre {
    background: var(--ink);
    color: #e5e7eb;
    border-radius: 8px;
    padding: 20px 24px;
    overflow-x: auto;
    margin: 24px 0;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
}

.content-column pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    color: inherit;
}

.content-column ul, .content-column ol {
    padding-left: 24px;
    margin-bottom: 20px;
}

.content-column li {
    margin-bottom: 8px;
}

.content-column li::marker {
    color: var(--ink-tertiary);
}

.content-column table {
    width: 100%;
    border-collapse: collapse;
    margin: 24px 0;
    font-size: 15px;
}

.content-column th {
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    padding: 10px 16px;
    background: var(--surface-sunken);
    border-bottom: 2px solid var(--border);
    color: var(--ink-secondary);
    letter-spacing: 0.01em;
}

.content-column td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.content-column hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 48px 0;
}

/* Section anchors */
.content-column section {
    scroll-margin-top: 80px;
}

/* Architecture diagram (preformatted) */
.arch-diagram {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink);
    margin: 24px 0;
}

/* ═══════════════════════════════════════════
   DISCUSS BUTTON
   ═══════════════════════════════════════════ */
.discuss-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--ink);
    color: white;
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 12px;
    text-decoration: none;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    transition: transform 0.2s var(--ease-out), box-shadow 0.2s ease;
}

.discuss-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.discuss-btn svg {
    width: 18px; height: 18px; fill: currentColor;
}

/* ═══════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════ */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 40px 48px;
    margin-left: var(--sidebar-w);
    text-align: center;
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--ink-tertiary);
    line-height: 1.7;
}

.site-footer a {
    color: var(--ink-secondary);
    text-decoration: none;
    border-bottom: 1px solid var(--ink-faint);
}

.site-footer a:hover {
    color: var(--brand);
    border-color: var(--brand);
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.35s var(--ease-out);
        z-index: 200;
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
        opacity: 1;
    }

    .toc-toggle {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .main-content {
        padding: 40px 24px 120px;
    }

    .site-footer {
        margin-left: 0;
        padding: 32px 24px;
    }
}

@media (max-width: 640px) {
    :root {
        --body-size: 17px;
    }

    .main-content {
        padding: 28px 18px 100px;
    }

    .article-header h1 {
        font-size: 28px;
    }

    .article-subtitle {
        font-size: 17px;
    }

    .content-column h2 {
        font-size: 23px;
    }

    .content-column table {
        font-size: 13px;
    }

    .content-column th, .content-column td {
        padding: 8px 10px;
    }

    .discuss-btn span { display: none; }
    .discuss-btn { padding: 14px; border-radius: 50%; }
}

/* ═══════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════ */
@media print {
    .wip-banner, .sidebar, .toc-toggle, .sidebar-overlay,
    .discuss-btn { display: none !important; }

    .main-content { padding: 0; }
    .site-footer { margin-left: 0; }

    .content-column {
        max-width: 100%;
        font-size: 12pt;
    }

    .content-column h2 { break-after: avoid; }
    .content-column pre { white-space: pre-wrap; word-break: break-all; }
    .content-column a { border: none; color: var(--ink); }
    .content-column a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #666; }
}

/* ═══════════════════════════════════════════
   LOAD ANIMATION
   ═══════════════════════════════════════════ */
.content-column {
    animation: contentFade 0.6s var(--ease-out) both;
}

@keyframes contentFade {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
