/* ============================================================
   Datasheet Theme — 芯片数据手册风格
   ============================================================ */

:root {
    --bg: #fff;
    --text: #1a1a1a;
    --text-muted: #555;
    --heading: #000;
    --accent: #003d7c;
    --accent-light: #e8f0f8;
    --th-bg: #e9ecf0;
    --th-border: #c0c4c8;
    --stripe: #f7f8f9;
    --cover-bg: #003d7c;
    --cover-text: #fff;
    --link: #005da0;
    --note-bg: #f5f7fa;
    --note-border: #003d7c;

    --font-body: "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
    --font-heading: "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
    --font-mono: "Cascadia Code", "Fira Code", Consolas, monospace;
    --size: 14px;
    --line: 1.7;
}

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

html { font-size: var(--size); }

body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: var(--line);
    color: var(--text);
    background: var(--bg);
    max-width: 900px;
    margin: 0 auto;
    padding: 0;
}

/* ---------- Cover ---------- */
.cover-page {
    width: 100%;
    box-sizing: border-box;
    padding: 0 2.5em;
    margin: 0 0 3em 0;
    min-height: 100vh;
    position: relative;
}
.cover-page-inner {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 100%;
    padding: 0 2.5em;
    box-sizing: border-box;
}
.cover-page .cover-meta {
    position: absolute;
    bottom: 40px;
    left: 0; right: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}
.cover-page::after {
    content: '';
    position: absolute;
    bottom: 0; left: 50%; transform: translateX(-50%);
    width: 60px; height: 1px;
    background: var(--th-border);
}
.cover-page .product-family {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    letter-spacing: 0.5em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 64px;
}
.cover-page h1 {
    font-family: var(--font-heading);
    font-size: 2.4rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 20px;
    color: var(--heading);
    border: none;
    padding: 0;
}
.cover-page .subtitle {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-bottom: 64px;
}
.cover-page .feature-list { display: none; }
.cover-page .cover-meta {
    position: absolute;
    bottom: 40px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.cover-page .cover-meta p { margin: 4px 0; }

/* ---------- Chapters ---------- */
.chapter { padding: 2em 2.5em; }

/* ---------- Headings ---------- */
h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--heading);
    margin: 2em 0 0.8em;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--accent);
}
h2 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin: 1.5em 0 0.6em;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--th-border);
}
h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--heading);
    margin: 1.2em 0 0.5em;
}
h4 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 1em 0 0.4em;
}

/* ---------- Body ---------- */
p { margin: 0.6em 0; text-align: justify; }
ul, ol { margin: 0.6em 0; padding-left: 2em; }
li { margin: 2px 0; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Tables ---------- */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 0.92rem;
}
thead th {
    background-color: var(--th-bg);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.88rem;
    text-align: left;
    padding: 6px 10px;
    border: 1px solid var(--th-border);
    border-bottom: 2px solid var(--accent);
    white-space: nowrap;
}
tbody td {
    padding: 5px 10px;
    border: 1px solid var(--th-border);
    vertical-align: top;
}
tbody tr:nth-child(even) { background-color: var(--stripe); }
table.compact { font-size: 0.82rem; }
table.compact thead th { font-size: 0.8rem; padding: 3px 7px; }
table.compact tbody td { padding: 3px 7px; }
td.addr, td.bits, td.reset-val { font-family: var(--font-mono); font-size: 0.85em; white-space: nowrap; }
td.bits { text-align: center; }

/* Permissions */
.perm-rw { color: #1a7a1a; font-weight: 600; }
.perm-ro { color: #b8860b; font-weight: 600; }
.perm-wc { color: #8b0000; font-weight: 600; }

/* ---------- Code ---------- */
code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--note-bg);
    padding: 1px 5px;
    border-radius: 2px;
    border: 1px solid var(--th-border);
}
pre {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background: var(--note-bg);
    border: 1px solid var(--th-border);
    border-left: 3px solid var(--accent);
    padding: 12px;
    margin: 1em 0;
    overflow-x: auto;
    line-height: 1.5;
}
pre code { background: none; padding: 0; border: none; font-size: inherit; }

/* Code block with line numbers (default @import display) */
.code-block {
    margin: 1em 0;
    border: 1px solid var(--th-border);
    border-radius: 3px;
    overflow: hidden;
}
.code-header {
    background: var(--th-bg);
    font-family: var(--font-heading);
    font-size: 0.78rem;
    padding: 4px 10px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--th-border);
}
.code-lines {
    margin: 0;
    border: none;
    border-left: none;
    font-size: 0.78rem;
    line-height: 1.55;
    padding: 8px 0;
    background: #fafbfc;
}
.code-lines .ln {
    display: inline-block;
    width: 40px;
    text-align: right;
    color: var(--text-muted);
    user-select: none;
    padding-right: 12px;
    margin-right: 8px;
    border-right: 1px solid var(--th-border);
}
.code-lines .lc {
    color: var(--text);
}

/* ---------- Figures ---------- */
figure {
    margin: 1.2em auto;
    text-align: center;
    max-width: 75%;
}
figure img {
    max-width: 100%;
    max-height: 420px;
    height: auto;
    border-radius: 3px;
}
figure figcaption {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}
/* Standalone images (not in figure) */
p img {
    max-width: 75%;
    max-height: 400px;
    height: auto;
    display: block;
    margin: 0.8em auto;
    border-radius: 3px;
}
/* Small images: inline icons, small diagrams */
img.img-sm, figure.img-sm { max-width: 40%; }
figure.img-sm img { max-height: 240px; }
/* Full-width: detailed block diagrams that need detail */
img.img-lg, figure.img-lg { max-width: 95%; }
figure.img-lg img { max-height: 600px; }
/* Images inside table cells — tighter constraints */
td img {
    max-width: 100%;
    max-height: 180px;
    margin: 0;
}
/* Side-by-side image row */
.img-row {
    display: flex;
    gap: 1em;
    justify-content: center;
    align-items: flex-start;
    margin: 1em 0;
}
.img-row img {
    flex: 0 0 auto;
    margin: 0;
    border-radius: 3px;
}

/* ---------- Blockquote / Notes ---------- */
blockquote {
    margin: 1em 0;
    padding: 10px 16px;
    border-left: 4px solid var(--note-border);
    background: var(--note-bg);
    font-size: 0.92rem;
}

/* ---------- TOC ---------- */
.toc { margin-bottom: 2em; }
.toc h2 { font-size: 1.4rem; border-bottom: 2px solid var(--accent); }
.toc-list { list-style: none; padding: 0; }
.toc-list li {
    padding: 4px 0;
    border-bottom: 1px dotted var(--th-border);
    display: flex;
    justify-content: space-between;
}
.toc-list li a { flex: 1; }

/* ---------- Sidebar (screen only) ---------- */
@media screen and (min-width: 1200px) {
    body { padding-left: 260px; max-width: 1100px; }
    .screen-toc {
        position: fixed;
        left: max(0px, calc((100vw - 1100px) / 2 - 240px));
        top: 0;
        width: 220px;
        height: 100vh;
        overflow-y: auto;
        background: var(--note-bg);
        border-right: 1px solid var(--th-border);
        padding: 16px 12px;
        font-size: 0.78rem;
        z-index: 100;
    }
    .cover-page { margin-left: calc(-2em - 260px + 2.5em); }
}

@media screen and (max-width: 1199px) {
    .screen-toc { display: none; }
}

.screen-toc ul { list-style: none; padding: 0; }
.screen-toc li { margin: 3px 0; line-height: 1.4; }
.screen-toc a { color: var(--text); display: block; padding: 2px 5px; border-radius: 2px; }
.screen-toc a:hover { background: var(--accent-light); text-decoration: none; }

/* ---------- Register summary ---------- */
.reg-summary { font-size: 0.9rem; }
.reg-summary strong { margin-right: 4px; }
.reg-summary code { margin-right: 12px; }

/* ---------- Warning ---------- */
.warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    padding: 10px;
    margin: 10px 0;
    border-radius: 3px;
}

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.text-mono { font-family: var(--font-mono); }
.page-break { margin: 2em 0; }

/* ---------- Auto-numbering ---------- */
body.auto-numbering { counter-reset: section; }
body.auto-numbering .chapter h1 { counter-increment: section; counter-reset: subsection; }
body.auto-numbering .chapter h1::before { content: counter(section) ". "; }
body.auto-numbering .chapter h2 { counter-increment: subsection; counter-reset: subsubsection; }
body.auto-numbering .chapter h2::before { content: counter(section) "." counter(subsection) " "; }
body.auto-numbering .chapter h3 { counter-increment: subsubsection; }
body.auto-numbering .chapter h3::before { content: counter(section) "." counter(subsection) "." counter(subsubsection) " "; }
