  :root, [data-theme="light"] {
    color-scheme: light;
    --bg: #ffffff;
    --bg-elevated: #ffffff;
    --bg-muted: #f5f5f5;
    --bg-subtle: #fafafa;
    --ink: #000000;
    --muted: #525252;
    --line: #e5e5e5;
    --line-strong: #a3a3a3;
    --on-brand: #ffffff;
    --shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 12px 32px rgba(0, 0, 0, .06);
    --radius: 12px;
    --font: "DM Sans", system-ui, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, monospace;
    --header-h: 64px;
    --sidebar-w: 340px;
  }
  [data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0a0a;
    --bg-elevated: #111111;
    --bg-muted: #1a1a1a;
    --bg-subtle: #141414;
    --ink: #fafafa;
    --muted: #a3a3a3;
    --line: #2a2a2a;
    --line-strong: #525252;
    --on-brand: #0a0a0a;
    --shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 12px 32px rgba(0, 0, 0, .45);
  }

  * { box-sizing: border-box; }
  html, body { min-height: 100%; }
  body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
  }
  button, input { font: inherit; }

  header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 30;
    height: var(--header-h);
    display: flex; align-items: center; gap: .75rem;
    padding: .65rem 1rem;
  }
  .topbar {
    flex: 1;
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    min-width: 0;
    padding: .45rem .55rem .45rem .65rem;
    background: var(--bg-elevated);
    border: 1px solid var(--line);
    border-radius: 999px;
  }
  .brand {
    display: flex; align-items: center; gap: .65rem;
    min-width: 0; flex: 1;
    font-weight: 700; letter-spacing: -.02em;
  }
  .brand-mark {
    width: 2rem; height: 2rem; flex: none;
    border-radius: 8px;
    background: var(--ink); color: var(--on-brand);
    display: grid; place-items: center;
    font-size: .78rem; font-weight: 700;
  }
  #docTitle {
    margin: 0; font-size: .95rem; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-actions { display: flex; align-items: center; gap: .35rem; flex: none; }

  .btn {
    appearance: none;
    border: 1px solid var(--ink);
    border-radius: 8px;
    padding: .4rem .75rem;
    background: var(--ink);
    color: var(--on-brand);
    font-weight: 600;
    font-size: .85rem;
    cursor: pointer;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
  }
  .btn:hover { opacity: .85; }
  .btn:disabled { opacity: .4; cursor: not-allowed; }
  .btn.secondary {
    background: var(--bg);
    color: var(--ink);
    border-color: var(--ink);
  }
  .btn.secondary:hover { background: var(--bg-muted); opacity: 1; }
  .btn.ghost {
    background: transparent;
    color: var(--muted);
    border-color: transparent;
  }
  .btn.ghost:hover { color: var(--ink); background: var(--bg-muted); opacity: 1; }
  .btn.icon {
    width: 2.15rem; height: 2.15rem; padding: 0;
    display: inline-grid; place-items: center;
    border-radius: 999px;
  }
  .btn.icon svg { width: 1.05rem; height: 1.05rem; display: block; }
  .btn.is-active {
    background: var(--ink);
    color: var(--on-brand);
  }

  .view-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
  }
  .view-toggle .btn {
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    padding: .35rem .65rem;
  }
  .view-toggle .btn + .btn { border-left: 1px solid var(--line); }
  .view-toggle .btn.is-active {
    background: var(--ink);
    color: var(--on-brand);
  }

  #menuBtn {
    width: 2.15rem; height: 2.15rem; flex: none;
    display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
    background: transparent; border: 0; border-radius: 999px; cursor: pointer; color: var(--ink);
  }
  #menuBtn:hover { background: var(--bg-muted); }
  #menuBtn span {
    width: 16px; height: 2px; background: currentColor; border-radius: 2px;
    transition: transform .25s, opacity .2s;
  }
  body.sidebar-open #menuBtn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  body.sidebar-open #menuBtn span:nth-child(2) { opacity: 0; }
  body.sidebar-open #menuBtn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  #sidebar {
    position: fixed; top: var(--header-h); bottom: 0; left: 0;
    width: var(--sidebar-w);
    background: var(--bg-elevated);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    transform: translateX(-100%); transition: transform .25s ease; z-index: 20;
  }
  body.sidebar-open #sidebar { transform: none; }

  .sidebar-head {
    padding: .85rem .85rem .5rem;
    display: flex; flex-direction: column; gap: .55rem;
  }
  .sidebar-label {
    font-size: .75rem; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--muted);
  }
  #search {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--ink);
    font-size: .9rem;
    outline: none;
  }
  #search:focus {
    outline: 2px solid var(--ink);
    outline-offset: 1px;
    border-color: var(--ink);
  }
  #search::placeholder { color: var(--muted); }

  #listStatus {
    padding: 0 .95rem .55rem;
    font-size: .78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }
  #listStatus .error {
    color: var(--ink);
    background: var(--bg-muted);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .7rem .75rem;
    margin: .25rem 0 .5rem;
    font-size: .82rem;
    line-height: 1.55;
  }
  #listStatus code {
    font-family: var(--mono);
    font-size: .78em;
    background: var(--bg-muted);
    padding: .05rem .3rem;
    border-radius: 4px;
    border: 1px solid var(--line);
  }

  #fileList {
    list-style: none; margin: 0;
    padding: .15rem .55rem 1rem;
    overflow-y: auto; flex: 1;
  }
  #fileList li {
    padding: .6rem .7rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: .88rem;
    line-height: 1.35;
    color: var(--ink);
  }
  #fileList li:hover { background: var(--bg-muted); }
  #fileList li.active {
    background: var(--ink);
    color: var(--on-brand);
    font-weight: 600;
  }
  #fileList li .meta {
    display: block;
    margin-top: .15rem;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    opacity: .7;
  }

  #backdrop {
    position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, .45);
    z-index: 15;
    opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  body.sidebar-open #backdrop { opacity: 1; pointer-events: auto; }

  #viewer {
    position: fixed; inset: var(--header-h) 0 0 0;
    transition: margin-left .25s ease;
    background: var(--bg-subtle);
  }

  #docStage {
    display: none;
    height: 100%;
    flex-direction: column;
    min-height: 0;
  }
  body.has-file #docStage { display: flex; }
  body.has-file #emptyState { display: none; }

  #docToolbar {
    flex: none;
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: .45rem .75rem;
    border-bottom: 1px solid var(--line);
    background: var(--bg-elevated);
    font-size: .82rem;
    color: var(--muted);
  }
  #docMeta { font-variant-numeric: tabular-nums; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #docStatus { min-height: 1.2em; }

  #mdView, #pdfView {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    display: none;
  }
  body.view-md #mdView { display: block; }
  body.view-pdf #pdfView { display: flex; flex-direction: column; }

  #mdView {
    padding: 1.25rem 1rem 2.5rem;
    background: var(--bg);
  }
  .md-article {
    max-width: 46rem;
    margin: 0 auto;
    line-height: 1.7;
    font-size: 1.02rem;
    overflow-wrap: anywhere;
    hyphens: auto;
  }
  .md-article h1, .md-article h2, .md-article h3, .md-article h4 {
    letter-spacing: -.02em;
    line-height: 1.3;
    margin: 1.55em 0 .55em;
    text-wrap: balance;
  }
  .md-article h1 {
    font-size: clamp(1.35rem, 2.4vw, 1.75rem);
    margin-top: 0;
    padding-bottom: .55rem;
    border-bottom: 1px solid var(--line);
  }
  .md-article h2 {
    font-size: 1.2rem;
    margin-top: 1.75em;
  }
  .md-article h3 {
    font-size: 1.05rem;
    color: var(--ink);
  }
  .md-article p {
    margin: .7em 0;
    text-align: justify;
    text-justify: inter-word;
  }
  .md-article hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1.25rem 0;
  }
  .md-article a { color: var(--ink); text-underline-offset: 2px; }
  .md-article a:hover { opacity: .7; }
  .md-article code, .md-article pre {
    font-family: var(--mono);
    font-size: .88em;
  }
  .md-article pre {
    overflow: auto;
    padding: .85rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-muted);
  }
  .md-article blockquote {
    margin: 1em 0;
    padding: .15rem 0 .15rem 1rem;
    border-left: 3px solid var(--line-strong);
    color: var(--muted);
  }
  .md-article ul, .md-article ol {
    padding-left: 1.35rem;
    margin: .65em 0;
  }
  .md-article li { margin: .28em 0; }
  .md-article li::marker { color: var(--muted); }
  .md-article table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
    margin: 1em 0;
  }
  .md-article th, .md-article td {
    border: 1px solid var(--line);
    padding: .45rem .55rem;
    text-align: left;
    vertical-align: top;
  }
  .md-article th { background: var(--bg-muted); }

  #pdfView {
    padding: 0;
    background: var(--bg-muted);
    min-height: 0;
  }
  .pdf-page {
    margin: 0 auto .75rem;
    background: #fff;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    border-radius: 4px;
    overflow: hidden;
    width: fit-content;
    max-width: 100%;
  }
  .pdf-page canvas {
    display: block;
    width: 100%;
    height: auto;
  }
  .pdf-page-placeholder {
    width: min(720px, 100%);
    height: 960px;
    margin: 0 auto .75rem;
    background: var(--bg-elevated);
    border: 1px dashed var(--line);
    border-radius: 4px;
  }

  #emptyState {
    height: 100%;
    display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 1.5rem;
  }
  #emptyState .card {
    width: min(420px, 100%);
    background: var(--bg-elevated);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem 1.25rem;
    box-shadow: var(--shadow);
  }
  #emptyState h2 {
    margin: 0 0 .35rem;
    font-size: 1.25rem;
    letter-spacing: -.02em;
  }
  #emptyState p {
    margin: 0;
    color: var(--muted);
    font-size: .92rem;
    line-height: 1.5;
  }
  .pill {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    background: var(--bg-muted);
    color: var(--ink);
    border: 1px solid var(--line);
    font-size: .78rem;
    font-weight: 600;
  }

  @media (min-width: 900px) {
    body.sidebar-open #viewer { margin-left: var(--sidebar-w); }
    #backdrop { display: none; }
  }
  @media (max-width: 720px) {
    header { padding: .55rem .65rem; }
    .topbar { border-radius: 16px; }
    #docTitle { font-size: .88rem; }
    .view-toggle .btn { padding: .35rem .5rem; font-size: .78rem; }
    #mdView { padding: 1rem .85rem 2rem; }
  }

  /* Search results */
  #fileList li .snippet {
    display: block;
    margin-top: .35rem;
    font-size: .78rem;
    line-height: 1.45;
    opacity: .85;
    font-weight: 400;
  }
  #fileList li mark {
    background: color-mix(in srgb, var(--ink) 18%, transparent);
    color: inherit;
    padding: 0 .1em;
    border-radius: 2px;
  }
  [data-theme="dark"] #fileList li mark {
    background: color-mix(in srgb, var(--ink) 22%, transparent);
  }
  #fileList li.active mark {
    background: color-mix(in srgb, var(--on-brand) 28%, transparent);
  }
  #fileList li.result-group-label {
    padding: .65rem .7rem .25rem;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    cursor: default;
    pointer-events: none;
  }
  #fileList li.result-group-label:hover { background: transparent; }

  /* Structured content (act TOC + section reader) */
  .content-article {
    max-width: 46rem;
    margin: 0 auto;
    line-height: 1.7;
    font-size: 1.02rem;
  }
  .content-article h1 {
    font-size: clamp(1.35rem, 2.4vw, 1.75rem);
    margin: 0 0 .55rem;
    letter-spacing: -.02em;
    line-height: 1.3;
    padding-bottom: .55rem;
    border-bottom: 1px solid var(--line);
    text-wrap: balance;
  }
  .content-article h2 {
    font-size: 1.15rem;
    margin: 1.6em 0 .55em;
    letter-spacing: -.02em;
  }
  .content-kicker {
    margin: 0 0 .35rem;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .content-meta {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: .9rem;
  }
  .section-body {
    white-space: pre-wrap;
    margin: 1rem 0;
    font-family: var(--font);
    line-height: 1.7;
    overflow-wrap: anywhere;
  }
  .parts-list {
    list-style: none;
    margin: 1rem 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .55rem;
  }
  .parts-list li {
    padding: .7rem .85rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-muted);
  }
  .parts-list .part-kind {
    display: block;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: .25rem;
  }
  .toc-chapter {
    margin: 1.25rem 0 .5rem;
    border-radius: 10px;
    padding: .15rem .35rem .35rem;
  }
  .toc-chapter.is-focus {
    background: var(--bg-muted);
    outline: 1px solid var(--line);
  }
  .toc-chapter h2 {
    margin: 0 0 .45rem;
    font-size: 1rem;
    color: var(--muted);
    font-weight: 700;
    letter-spacing: .02em;
  }
  .toc-chapter.is-focus h2 {
    color: var(--ink);
  }
  .toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .toc-list li {
    margin: 0;
  }
  .toc-list a {
    display: block;
    padding: .5rem .65rem;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    font-size: .92rem;
    line-height: 1.35;
  }
  .toc-list a:hover { background: var(--bg-muted); }
  .toc-list .sec-num {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-right: .35rem;
  }
  .nav-adjacent {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-top: 1.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
  }
  .nav-adjacent a {
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    font-size: .9rem;
  }
  .nav-adjacent a:hover { opacity: .7; }
  .nav-adjacent .muted { color: var(--muted); font-weight: 500; }
  .defs-list, .notes-list {
    margin: 1rem 0;
    padding-left: 1.2rem;
  }
  .defs-list li, .notes-list li {
    margin: .4em 0;
  }
  #pdfFrame {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    background: var(--bg-muted);
  }
