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

body {
    font-family: var(--font-serif);
    color: var(--ink);
    background: var(--parchment);
    line-height: 1.68;
}

/* ── Skip link (A19, A20) ── */

.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    padding: 0.75rem 1.5rem;
    background: var(--ink);
    color: var(--parchment);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    z-index: 1000;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
}

/* ── Focus indicators (A7–A9) ── */

:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* ── Reduced motion (A10–A12) ── */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Header ── */

header {
    background: var(--parchment);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--grid);
    transition: transform 0.24s ease;
}

#navbar {
    max-width: calc(var(--measure) + 14rem);
    margin: 0 auto;
    padding: 0.85rem var(--gutter);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: nowrap;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.logo {
    width: 2rem;
    height: 2rem;
    width: auto;
}

.brand-lockup {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
}

.wordmark {
    width: 7.05rem;
    height: auto;
}

.site-title {
    color: var(--stone);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    white-space: nowrap;
}

.menu-toggle {
    display: none;
    border: 1px solid var(--grid);
    background: var(--warm-white);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    min-height: var(--min-target-aa);
    padding: 0.55rem 0.75rem;
    align-items: center;
    gap: 0.7rem;
    margin-left: auto;
}

.menu-toggle-icon {
    display: inline-flex;
    flex-direction: column;
    gap: 0.2rem;
}

.menu-toggle-icon span {
    display: block;
    width: 1rem;
    height: 1px;
    background: currentColor;
}

.nav-panel {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
}

/* ── Navigation ── */

#nav-links {
    display: flex;
    list-style: none;
    gap: 0.35rem;
    flex-wrap: wrap;
    flex: 1;
    font-family: var(--font-mono);
}

.nav-item {
    position: relative;
}

.nav-link-row {
    display: flex;
    align-items: stretch;
}

.nav-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--warm-white);
    list-style: none;
    min-width: 12rem;
    border: 1px solid var(--grid);
    z-index: 200;
    padding: 0.25rem 0;
}

.nav-item:hover .nav-dropdown,
.nav-item:focus-within .nav-dropdown,
.nav-item.is-open .nav-dropdown {
    display: block;
}

.nav-section-toggle {
    display: none;
    border: 0;
    background: transparent;
    color: var(--stone);
    padding: 0.3rem 0.45rem;
    min-height: var(--min-target-aa);
    min-width: var(--min-target-aa);
    align-items: center;
    justify-content: center;
}

.nav-section-toggle-icon {
    display: inline-flex;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg) translateY(-1px);
    transition: transform 0.15s ease;
}

.nav-item.is-open .nav-section-toggle-icon {
    transform: rotate(225deg) translateY(-1px);
}

.nav-dropdown li a {
    display: block;
    padding: 0.35rem 0.75rem;
    white-space: nowrap;
    min-height: var(--min-target-aa);
}

#nav-links li > a,
.nav-link-row > a {
    color: var(--ink);
    text-decoration: none;
    padding: 0.3rem 0.45rem;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    min-height: var(--min-target-aa);
    display: inline-flex;
    align-items: center;
}

@media (prefers-reduced-motion: no-preference) {
    #nav-links li > a,
    .nav-link-row > a,
    .menu-toggle,
    .repo-link {
        transition: color 0.15s, background 0.15s;
    }
}

#nav-links li > a:hover,
#nav-links li > a.active,
.nav-link-row > a:hover,
.nav-link-row > a.active,
.nav-section-toggle:hover {
    color: var(--sea);
    background: var(--warm-white);
}

.repo-link {
    color: var(--stone);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    min-height: var(--min-target-aa);
    display: inline-flex;
    align-items: center;
    margin-left: auto;
}

.repo-link:hover {
    color: var(--sea);
}

/* ── Main content ── */

main {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 2rem auto;
    padding: 0 var(--gutter);
}

#content {
    background: var(--warm-white);
    padding: 2.35rem;
    border: 1px solid var(--grid);
}

.loading {
    color: var(--stone);
    font-style: italic;
}

/* ── Endorsement marker ── */

.endorsement {
    margin-bottom: 1.5rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid var(--grid);
}

.endorsement-label,
.endorsement-scope {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.endorsement-label {
    color: var(--signal);
    margin-bottom: 0.3rem;
}

.endorsement-scope {
    color: var(--stone);
}

/* ── Typography ── */

#content h1 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--grid);
}

#content h2 {
    font-size: 1.4rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--sea);
}

#content h3 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

#content p {
    margin-bottom: 0.75rem;
}

#content a {
    color: var(--sea);
}

#content ul, #content ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

#content li {
    margin-bottom: 0.25rem;
}

/* ── Tables (Section 10, TB1–TB10, TF1–TF6) ── */

#content table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-variant-numeric: tabular-nums;
    margin-block: 1.2rem;
}

#content th {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--ink);
    text-align: left;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--stone);
    background: transparent;
    vertical-align: bottom;
}

#content td {
    font-family: var(--font-serif);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--ink);
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--grid);
    vertical-align: top;
}

th.num, td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

@media (hover: hover) {
    #content tbody tr:hover {
        background: var(--warm-white);
    }
}

/* ── Code ── */

#content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--parchment);
    padding: 0.15em 0.35em;
    border-radius: 3px;
}

#content pre {
    background: var(--parchment);
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--grid);
}

#content pre code {
    background: none;
    padding: 0;
}

/* ── KaTeX ── */

.katex-display {
    margin: 1rem 0;
    overflow-x: auto;
}

/* ── Blockquote ── */

blockquote {
    margin: 1rem 0;
    padding-left: 1rem;
    border-left: 3px solid var(--sea);
    color: var(--stone);
}

/* ── Section rule ── */

hr {
    width: 1.5rem;
    margin: 1.8rem 0 1.2rem;
    border: 0;
    border-top: 1px solid var(--grid);
}

/* ── Footer ── */

footer {
    max-width: calc(var(--measure) + 2 * var(--gutter));
    margin: 0 auto 2rem;
    padding: 0 var(--gutter);
    color: var(--stone);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

footer a {
    color: var(--sea);
    text-decoration: none;
}

/* ── YAML table ── */

.yaml-table {
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.yaml-table td:first-child {
    font-weight: 600;
    color: var(--sea);
    white-space: nowrap;
}

/* ── Mobile table scroll wrapper (TB6–TB7) ── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
}

/* ── Mobile (≤ 640px) ── */

@media (max-width: 640px) {
    :root {
        --gutter: 1.25rem;
    }

    header {
        will-change: transform;
    }

    header.is-hidden {
        transform: translateY(calc(-100% - 1px));
    }

    #navbar {
        align-items: center;
        gap: 0.75rem;
        position: relative;
    }

    #content {
        padding: 1.4rem;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .nav-panel {
        display: none;
        position: absolute;
        top: calc(100% + 0.75rem);
        left: var(--gutter);
        right: var(--gutter);
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 0.85rem;
        background: var(--warm-white);
        border: 1px solid var(--grid);
        box-shadow: 0 0.85rem 2rem rgba(33, 43, 48, 0.08);
    }

    header.menu-open .nav-panel {
        display: flex;
    }

    #nav-links {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }

    .nav-item {
        width: 100%;
        border-bottom: 1px solid var(--grid);
    }

    .nav-item:last-child {
        border-bottom: 0;
    }

    .nav-link-row {
        width: 100%;
        justify-content: space-between;
    }

    .nav-dropdown {
        position: static;
        min-width: 0;
        margin-top: 0;
        padding: 0 0 0.4rem;
        border: 0;
        border-top: 1px solid var(--grid);
        background: transparent;
    }

    .nav-item:hover .nav-dropdown,
    .nav-item:focus-within .nav-dropdown {
        display: none;
    }

    .nav-item.is-open .nav-dropdown {
        display: block;
    }

    .nav-section-toggle {
        display: inline-flex;
    }

    #nav-links li > a,
    .nav-link-row > a,
    .nav-dropdown li a {
        min-height: var(--min-target-aa);
        padding: 0.7rem 0.1rem;
        width: 100%;
    }

    .nav-dropdown li a {
        padding-left: 0.65rem;
        font-size: 0.72rem;
        color: var(--stone);
    }

    .repo-link {
        width: 100%;
        justify-content: center;
        margin-left: 0;
        padding-top: 0.25rem;
    }
}
