/* ==========================================================================
   layer-2.wiki — documentation clean slate
   Palette: white (#ffffff) / code-gray (#f6f8fa) / wiki-blue (#1a73e8)
            amber (#d29922) / green (#1a7f37) / border (#d0d7de #e0e0e0)
   Type: Literata (display) · Source Sans 3 (body) · Source Code Pro (mono)

   Implementation notes (per DESIGN.md):
   - Header bar 64px, fixed, white, bottom border 1px #e0e0e0
   - Sidebar 280px, sticky, code-gray background
   - Main content max-width 760px
   - Scroll-spy: IntersectionObserver on all H2/H3 elements.
     When a heading enters the viewport, update active TOC item and
     slide the blue left-border indicator (3px #1a73e8).
   - Search highlight: 2s yellow (#fff8c5) fade on navigated section.
   - Info boxes: Note (blue), Warning (amber), Tip (green) — left border 4px.
   - Fonts loaded via (Google Fonts):
       Literata, Source Sans 3, Source Code Pro
   ========================================================================== */

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

:root {
    --c-bg:        #ffffff;   /* primary background */
    --c-surface:   #f6f8fa;   /* code gray */
    --c-link:      #1a73e8;   /* wiki blue */
    --c-text:      #1f2328;   /* near black */
    --c-border:    #d0d7de;   /* light gray */
    --c-muted:     #656d76;   /* medium gray */
    --c-highlight: #fff8c5;   /* pale yellow */
    --c-amber:     #d29922;
    --c-green:     #1a7f37;

    --header-h: 64px;
    --sidebar-w: 280px;
    --outline-w: 220px;
    --content-max: 760px;

    --ff-display: "Literata", "Source Serif Pro", Georgia, serif;
    --ff-body: "Source Sans 3", "Inter", system-ui, sans-serif;
    --ff-mono: "Source Code Pro", "SF Mono", Menlo, Consolas, monospace;
}

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

body {
    background: var(--c-bg);
    color: var(--c-text);
    font-family: var(--ff-body);
    font-size: 1rem;
    line-height: 1.8;
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ============================ HEADER ============================ */
.site-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--c-bg);
    border-bottom: 1px solid var(--c-border);
    z-index: 100;
    transition: box-shadow 0.2s ease;
}
.site-header.is-scrolled {
    box-shadow: 0 1px 0 rgba(31, 35, 40, 0.04), 0 4px 12px rgba(31, 35, 40, 0.04);
}
.header-inner {
    height: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 2rem;
    padding: 0 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    color: var(--c-text);
    font-family: var(--ff-display);
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.brand-mark {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--c-link);
    transition: transform 0.25s ease, border-color 0.25s ease;
}
.brand:hover .brand-mark {
    transform: rotate(-6deg);
    border-color: var(--c-link);
}
.brand-name { font-family: var(--ff-display); }
.brand-dot { color: var(--c-link); }

.header-categories {
    display: flex;
    align-items: center;
    gap: 1.4rem;
    justify-self: center;
}
.header-categories a {
    color: var(--c-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.4rem 0;
    position: relative;
    transition: color 0.18s ease;
}
.header-categories a::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -2px;
    height: 2px;
    background: var(--c-link);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.22s ease;
}
.header-categories a:hover {
    color: var(--c-text);
}
.header-categories a:hover::after { transform: scaleX(1); }

.header-search {
    position: relative;
    display: flex;
    align-items: center;
    width: 360px;
    max-width: 360px;
}
.header-search .search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--c-muted);
    display: inline-flex;
    pointer-events: none;
}
#searchInput {
    width: 100%;
    height: 36px;
    padding: 0 2.4rem 0 2.2rem;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    background: var(--c-bg);
    font-family: var(--ff-body);
    font-size: 0.9rem;
    color: var(--c-text);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
#searchInput::placeholder { color: var(--c-muted); }
#searchInput:focus {
    outline: none;
    border-color: var(--c-link);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.18);
    background: var(--c-bg);
}
.search-kbd {
    position: absolute;
    right: 0.65rem;
    font-family: var(--ff-mono);
    font-size: 0.7rem;
    color: var(--c-muted);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 1px 6px;
    pointer-events: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(31, 35, 40, 0.08);
    list-style: none;
    max-height: 360px;
    overflow-y: auto;
    z-index: 110;
}
.search-results[hidden] { display: none; }
.search-results li {
    padding: 0.65rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--c-border);
    transition: background 0.12s ease;
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover,
.search-results li.is-active {
    background: var(--c-surface);
}
.search-results .res-title {
    font-weight: 500;
    color: var(--c-text);
    font-size: 0.92rem;
}
.search-results .res-section {
    font-size: 0.75rem;
    color: var(--c-muted);
    margin-top: 2px;
}
.search-results .res-empty {
    padding: 0.8rem 1rem;
    color: var(--c-muted);
    font-size: 0.9rem;
    cursor: default;
}
.search-results .res-empty:hover { background: transparent; }

/* ============================ LAYOUT ============================ */
.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr var(--outline-w);
    max-width: 1600px;
    margin: 0 auto;
    padding-top: var(--header-h);
}

/* ============================ SIDEBAR ============================ */
.sidebar {
    position: sticky;
    top: var(--header-h);
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    padding: 1.5rem 0.5rem 2rem;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 4px; }

.sidebar-section { padding: 0 0.5rem 1.25rem; position: relative; }
.sidebar-heading {
    font-family: var(--ff-body);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--c-muted);
    margin: 0.5rem 0.75rem 0.6rem;
}

.toc { list-style: none; position: relative; }
.toc-item { position: relative; }
.toc-item a {
    display: block;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--c-muted);
    text-decoration: none;
    padding: 0.3rem 0.75rem;
    border-left: 3px solid transparent;
    transition: color 0.18s ease, background 0.18s ease;
}
.toc-item a:hover {
    color: var(--c-text);
    background: rgba(208, 215, 222, 0.35);
}
.toc-item.toc-sub a {
    padding-left: 1.6rem;
    font-size: 0.83rem;
}
.toc-item.is-active a {
    color: var(--c-text);
    font-weight: 500;
    border-left-color: var(--c-link);
    background: rgba(26, 115, 232, 0.06);
}

.toc-indicator {
    position: absolute;
    left: 0.5rem;
    width: 3px;
    background: var(--c-link);
    border-radius: 2px;
    top: 0;
    height: 0;
    transition: top 0.32s cubic-bezier(0.4, 0, 0.2, 1), height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    opacity: 0;
}
.toc-indicator.is-visible { opacity: 1; }

.sidebar-footer { border-top: 1px solid var(--c-border); padding-top: 1rem; margin-top: 0.5rem; }
.meta-list { list-style: none; padding: 0 0.75rem; }
.meta-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.8rem;
    color: var(--c-muted);
    padding: 0.25rem 0;
}
.meta-list strong {
    color: var(--c-text);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ============================ CONTENT ============================ */
.content {
    min-width: 0;
    padding: 2rem 3rem 6rem;
}
.article {
    max-width: var(--content-max);
    margin: 0 auto;
}

.breadcrumb {
    font-size: 0.82rem;
    color: var(--c-muted);
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}
.breadcrumb a {
    color: var(--c-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}
.breadcrumb a:hover { color: var(--c-link); text-decoration: underline; }
.crumb-sep { color: var(--c-border); }
.crumb-current { color: var(--c-text); font-weight: 500; }

.article-head { margin-bottom: 2.25rem; }
.article-title {
    font-family: var(--ff-display);
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    line-height: 1.18;
    color: var(--c-text);
    letter-spacing: -0.015em;
    border-bottom: 1px solid var(--c-border);
    padding-bottom: 0.5rem;
    margin-bottom: 1.25rem;
}

.article-summary {
    font-size: 1.08rem;
    line-height: 1.7;
    color: var(--c-muted);
    margin-bottom: 1.25rem;
    font-family: var(--ff-display);
    font-style: italic;
    font-weight: 400;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem 2rem;
    list-style: none;
    font-size: 0.85rem;
    color: var(--c-muted);
    padding: 0.75rem 0;
    border-top: 1px solid var(--c-border);
    border-bottom: 1px solid var(--c-border);
}
.meta-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.7rem;
    color: var(--c-muted);
    margin-right: 0.4rem;
    font-weight: 600;
}
.status-pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid;
}
.status-stable {
    color: var(--c-green);
    border-color: var(--c-green);
    background: rgba(26, 127, 55, 0.06);
}

/* sections */
.section { padding: 1rem 0 0.5rem; }
.section-title {
    font-family: var(--ff-display);
    font-weight: 600;
    font-size: 1.6rem;
    line-height: 1.3;
    color: var(--c-text);
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--c-border);
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
    scroll-margin-top: calc(var(--header-h) + 16px);
}
.section:first-of-type .section-title:first-child { margin-top: 1rem; padding-top: 0; border-top: none; }
.section-sub { padding: 0; }
.section-subtitle {
    font-family: var(--ff-display);
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--c-text);
    margin: 2rem 0 0.75rem;
    scroll-margin-top: calc(var(--header-h) + 16px);
}

.section p,
.article-foot p {
    color: var(--c-text);
    margin-bottom: 1rem;
    font-size: 1rem;
    line-height: 1.8;
}
.section em { font-style: italic; }
.section strong { font-weight: 600; color: var(--c-text); }

/* inline links */
.section a, .article-foot a, .xref {
    color: var(--c-link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.section a:hover, .xref:hover {
    border-bottom-color: var(--c-link);
}

/* inline code */
code, .section code {
    font-family: var(--ff-mono);
    font-size: 0.88em;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 4px;
    padding: 0.05em 0.4em;
    color: var(--c-text);
}

/* code block */
.code-block {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    font-family: var(--ff-mono);
    font-size: 0.86rem;
    line-height: 1.7;
    overflow-x: auto;
    margin: 1.25rem 0;
    color: var(--c-text);
    white-space: pre;
}
.code-block code {
    background: transparent;
    border: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
}
.tok-keyword { color: #cf222e; font-weight: 500; }
.tok-string  { color: #0a3069; }
.tok-number  { color: #0550ae; }
.tok-comment { color: var(--c-muted); font-style: italic; }
.tok-fn      { color: #8250df; }
.tok-type    { color: var(--c-amber); }

/* ============================ CALLOUTS ============================ */
.callout {
    padding: 0.85rem 1.1rem 0.9rem;
    border-left: 4px solid;
    border-radius: 4px;
    margin: 1.25rem 0;
    background: var(--c-surface);
}
.callout p { margin: 0; font-size: 0.96rem; line-height: 1.65; }
.callout-label {
    font-family: var(--ff-body);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.3rem;
}
.callout-note {
    border-color: var(--c-link);
    background: rgba(26, 115, 232, 0.06);
}
.callout-note .callout-label { color: var(--c-link); }
.callout-warning {
    border-color: var(--c-amber);
    background: rgba(210, 153, 34, 0.08);
}
.callout-warning .callout-label { color: var(--c-amber); }
.callout-tip {
    border-color: var(--c-green);
    background: rgba(26, 127, 55, 0.06);
}
.callout-tip .callout-label { color: var(--c-green); }

/* ============================ TABLE ============================ */
.table-wrap {
    overflow-x: auto;
    margin: 1.25rem 0;
    border: 1px solid var(--c-border);
    border-radius: 8px;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}
.data-table th, .data-table td {
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    border-right: 1px solid var(--c-border);
}
.data-table th:last-child, .data-table td:last-child { border-right: none; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table thead th {
    background: var(--c-surface);
    font-weight: 600;
    color: var(--c-text);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: var(--header-h);
}
.data-table tbody tr:nth-child(even) td { background: var(--c-surface); }
.data-table tbody tr:nth-child(odd) td  { background: var(--c-bg); }

/* ============================ ECOSYSTEM LIST ============================ */
.ecosystem-list { list-style: none; margin: 1rem 0; }
.ecosystem-list li {
    padding: 0.55rem 0 0.55rem 1.5rem;
    border-bottom: 1px solid var(--c-border);
    position: relative;
    font-size: 0.95rem;
}
.ecosystem-list li::before {
    content: "▸";
    position: absolute;
    left: 0.25rem;
    color: var(--c-link);
    font-size: 0.8rem;
    top: 0.7rem;
}
.ecosystem-list li:last-child { border-bottom: none; }

/* ============================ GLOSSARY ============================ */
.glossary { margin-top: 1.25rem; border-top: 1px solid var(--c-border); }
.glossary dt {
    font-family: var(--ff-display);
    font-weight: 600;
    color: var(--c-text);
    font-size: 1.02rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--c-border);
}
.glossary dt:first-of-type { border-top: none; padding-top: 0; }
.glossary dd {
    color: var(--c-text);
    font-size: 0.95rem;
    line-height: 1.7;
    margin: 0.25rem 0 0;
    padding-left: 0;
}

/* ============================ REFERENCES ============================ */
.references {
    list-style: none;
    counter-reset: refs;
    margin-top: 1rem;
}
.references li {
    font-size: 0.9rem;
    color: var(--c-text);
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    gap: 0.5rem;
}
.references li:last-child { border-bottom: none; }
.ref-num {
    color: var(--c-link);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    flex-shrink: 0;
}

/* ============================ ARTICLE FOOTER ============================ */
.article-foot {
    margin-top: 4rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--c-border);
    color: var(--c-muted);
    font-size: 0.88rem;
}
.article-foot p { color: var(--c-muted); font-size: 0.88rem; }
.edit-info { margin-top: 0.5rem; font-size: 0.82rem; }
.edit-info code { font-size: 0.8rem; }

/* ============================ PAGE OUTLINE ============================ */
.page-outline {
    position: sticky;
    top: var(--header-h);
    align-self: start;
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 2rem 1rem 2rem 0.5rem;
    border-left: 1px solid var(--c-border);
}
.outline-heading {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--c-muted);
    font-weight: 600;
    margin-bottom: 0.6rem;
    padding-left: 0.5rem;
}
.outline-list { list-style: none; }
.outline-list li { margin: 0; }
.outline-list a {
    display: block;
    font-size: 0.82rem;
    color: var(--c-muted);
    padding: 0.25rem 0.75rem;
    border-left: 2px solid transparent;
    text-decoration: none;
    transition: color 0.18s ease, border-color 0.18s ease;
}
.outline-list a:hover { color: var(--c-text); }
.outline-list a.is-active {
    color: var(--c-link);
    border-left-color: var(--c-link);
    font-weight: 500;
}
.outline-footer { margin-top: 1rem; padding: 0 0.5rem; }
.outline-top {
    background: transparent;
    border: 1px solid var(--c-border);
    color: var(--c-muted);
    font-family: var(--ff-body);
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.outline-top:hover {
    color: var(--c-link);
    border-color: var(--c-link);
    background: var(--c-surface);
}

/* ============================ SEARCH HIGHLIGHT ============================ */
.search-flash {
    animation: searchFlash 2s ease-out;
}
@keyframes searchFlash {
    0%   { background: var(--c-highlight); box-shadow: 0 0 0 6px var(--c-highlight); }
    60%  { background: var(--c-highlight); box-shadow: 0 0 0 6px var(--c-highlight); }
    100% { background: transparent; box-shadow: 0 0 0 6px transparent; }
}

mark.search-mark {
    background: var(--c-highlight);
    color: var(--c-text);
    padding: 0 2px;
    border-radius: 2px;
}

/* ============================ RESPONSIVE ============================ */
@media (max-width: 1180px) {
    .layout { grid-template-columns: var(--sidebar-w) 1fr; }
    .page-outline { display: none; }
}
@media (max-width: 900px) {
    .header-categories { display: none; }
    .header-search { width: 220px; }
    .header-inner { gap: 1rem; padding: 0 1.25rem; }
}
@media (max-width: 720px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--c-border);
    }
    .content { padding: 1.25rem 1.25rem 4rem; }
    .article-meta { gap: 0.6rem 1.25rem; }
    .header-search { width: 100%; max-width: none; }
    .brand-name { font-size: 0.95rem; }
}
