/* The CNA Bible — HTML edition
   Layout: a fixed table-of-contents rail, a measured reading column, and an
   on-this-page rail that folds away below 1280px.  Colours are defined once as
   tokens on :root and re-declared for the dark theme, so every rule below works
   in both without repeating itself. */

:root {
  color-scheme: light;
  --bg: #fbfaf8;
  --bg-raised: #ffffff;
  --bg-sunken: #f2f0ec;
  --bg-code: #f6f5f2;
  --fg: #1d1c1a;
  --fg-muted: #5d5a54;
  --fg-faint: #8b877f;
  --rule: #e2ded6;
  --rule-strong: #cbc5ba;
  --accent: #1a5b8a;
  --accent-soft: #e8f0f6;
  --link: #14567f;
  --link-visited: #5a4a86;

  --note-source-bg: #eef4fa;
  --note-source-line: #2b6ea6;
  --note-contract-bg: #e6eef7;
  --note-contract-line: #24558a;
  --note-evidence-bg: #e9f4ea;
  --note-evidence-line: #3b7a44;
  --note-history-bg: #f2f1ef;
  --note-history-line: #7d7a73;
  --note-limitation-bg: #fbf1e0;
  --note-limitation-line: #a86a1a;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
           Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Mono", Menlo, Consolas,
          "Liberation Mono", monospace;

  --rail: 21rem;
  --aside: 16rem;
  --header-h: 3.5rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181c;
  --bg-raised: #1c1f24;
  --bg-sunken: #121417;
  --bg-code: #1b1e23;
  --fg: #e6e3dd;
  --fg-muted: #a9a49b;
  --fg-faint: #7d7970;
  --rule: #2c3037;
  --rule-strong: #3d434c;
  --accent: #7fb6de;
  --accent-soft: #1d2a35;
  --link: #83bce4;
  --link-visited: #b7a4dd;

  --note-source-bg: #182430;
  --note-source-line: #4d90c4;
  --note-contract-bg: #17222f;
  --note-contract-line: #558bc0;
  --note-evidence-bg: #17251a;
  --note-evidence-line: #5fa26a;
  --note-history-bg: #1d1f22;
  --note-history-line: #6f6c66;
  --note-limitation-bg: #2a2114;
  --note-limitation-line: #c08c3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16181c;
    --bg-raised: #1c1f24;
    --bg-sunken: #121417;
    --bg-code: #1b1e23;
    --fg: #e6e3dd;
    --fg-muted: #a9a49b;
    --fg-faint: #7d7970;
    --rule: #2c3037;
    --rule-strong: #3d434c;
    --accent: #7fb6de;
    --accent-soft: #1d2a35;
    --link: #83bce4;
    --link-visited: #b7a4dd;

    --note-source-bg: #182430;
    --note-source-line: #4d90c4;
    --note-contract-bg: #17222f;
    --note-contract-line: #558bc0;
    --note-evidence-bg: #17251a;
    --note-evidence-line: #5fa26a;
    --note-history-bg: #1d1f22;
    --note-history-line: #6f6c66;
    --note-limitation-bg: #2a2114;
    --note-limitation-line: #c08c3a;
  }
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 1rem); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 2px; }

.cna-skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 6px 0;
}
.cna-skip:focus { left: 0; }

/* ----------------------------------------------------------------- header */
.cna-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  height: var(--header-h);
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  backdrop-filter: saturate(150%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.cna-brand {
  display: flex; align-items: baseline; gap: .6rem;
  font-family: var(--sans); text-decoration: none; color: inherit;
  min-width: 0;
}
.cna-brand strong { font-size: 1rem; letter-spacing: .01em; white-space: nowrap; }
.cna-edition {
  font-size: .8rem; color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cna-actions { margin-left: auto; display: flex; gap: .4rem; }

.cna-header button {
  font: inherit; font-family: var(--sans); font-size: .85rem;
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .35rem .7rem;
  color: var(--fg); background: transparent;
  border: 1px solid var(--rule-strong); border-radius: 6px; cursor: pointer;
}
.cna-header button:hover { background: var(--bg-sunken); }
.cna-menu { display: none; }

/* ------------------------------------------------------------------ shell */
.cna-shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr) var(--aside);
  align-items: start;
  max-width: 108rem;
  margin: 0 auto;
}

.cna-sidebar, .cna-onpage {
  position: sticky; top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: var(--sans);
}
.cna-sidebar { border-right: 1px solid var(--rule); padding: 1.25rem .75rem 3rem; }
.cna-onpage { padding: 1.75rem 1rem 3rem; }

.cna-main { min-width: 0; padding: 1.25rem 2.5rem 4rem; }

/* --------------------------------------------------------- sidebar contents */
.cna-toc-list, .cna-toc-sub { list-style: none; margin: 0; padding: 0; }
.cna-toc-sub { margin: .15rem 0 .5rem .55rem; border-left: 1px solid var(--rule); }
.cna-toc-link {
  display: flex; gap: .5rem; align-items: baseline;
  padding: .3rem .55rem; border-radius: 5px;
  font-size: .875rem; line-height: 1.35;
  color: var(--fg-muted); text-decoration: none;
}
.cna-toc-link:visited { color: var(--fg-muted); }
.cna-toc-link:hover { background: var(--bg-sunken); color: var(--fg); }
.cna-toc-link[aria-current="page"] {
  background: var(--accent-soft); color: var(--fg); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.cna-toc-part > .cna-toc-link {
  margin-top: .9rem; font-size: .78rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--fg);
}
.cna-toc-home > .cna-toc-link, .cna-toc-front > .cna-toc-link { font-weight: 600; color: var(--fg); }
.cna-num { color: var(--fg-faint); font-variant-numeric: tabular-nums; flex: none; }
.cna-toc-sub .cna-num { min-width: 1.5rem; }

/* -------------------------------------------------------------- on this page */
.cna-onpage-title {
  font-size: .72rem; letter-spacing: .09em; text-transform: uppercase;
  color: var(--fg-faint); margin: 0 0 .5rem;
}
.cna-onpage-list { list-style: none; margin: 0; padding: 0; font-size: .82rem; }
.cna-onpage-list a {
  display: block; padding: .18rem .5rem; border-left: 2px solid transparent;
  color: var(--fg-muted); text-decoration: none; line-height: 1.4;
}
.cna-onpage-list a:hover { color: var(--fg); }
.cna-onpage-list a.is-active { border-left-color: var(--accent); color: var(--fg); }
.cna-onpage-l2 a { padding-left: 1.3rem; font-size: .78rem; }

/* ------------------------------------------------------------ breadcrumb/pager */
.cna-breadcrumb {
  font-family: var(--sans); font-size: .8rem; color: var(--fg-muted);
  margin-bottom: 1.5rem;
}
.cna-breadcrumb a { color: var(--fg-muted); text-decoration: none; }
.cna-breadcrumb a:hover { color: var(--fg); text-decoration: underline; }
.cna-sep { color: var(--fg-faint); padding: 0 .1rem; }

.cna-pager {
  display: flex; gap: 1rem; margin-top: 3.5rem; padding-top: 1.5rem;
  border-top: 1px solid var(--rule); font-family: var(--sans);
}
.cna-pager a {
  flex: 1; display: flex; flex-direction: column; gap: .15rem;
  padding: .8rem 1rem; border: 1px solid var(--rule); border-radius: 8px;
  text-decoration: none; color: var(--fg); background: var(--bg-raised);
}
.cna-pager a:hover { border-color: var(--accent); }
.cna-next { text-align: right; }
.cna-pager-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); }
.cna-pager-title { font-size: .9rem; }

/* -------------------------------------------------------------- book content */
.cna-article { max-width: 46rem; }
.cna-page-index .cna-article, .cna-page-home .cna-article { max-width: 58rem; }

.cna-article h1, .cna-article h2, .cna-article h3, .cna-article h4 {
  font-family: var(--sans); line-height: 1.25; text-wrap: balance;
  margin: 2.4rem 0 .8rem;
}
.cna-article h1 { font-size: 2.05rem; margin-top: .5rem; letter-spacing: -.015em; }
.cna-article h2 { font-size: 1.4rem; margin-top: 2.8rem; }
.cna-article h3 { font-size: 1.1rem; margin-top: 2rem; }
.cna-article h4 { font-size: .98rem; }
.cna-article h1 .ltx_tag { display: block; font-size: .72rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--accent); margin-bottom: .35rem; }
.cna-article h2 .ltx_tag, .cna-article h3 .ltx_tag { color: var(--fg-faint); font-weight: 500; }

.ltx_para { margin: 0 0 1.15rem; }
.ltx_p { margin: 0 0 1.05rem; hyphens: auto; }
.ltx_p:last-child { margin-bottom: 0; }

.ltx_font_typewriter, .ltx_lst_identifier {
  font-family: var(--mono); font-size: .875em;
}
.ltx_p .ltx_font_typewriter, .ltx_item > .ltx_font_typewriter {
  background: var(--bg-code); border: 1px solid var(--rule);
  border-radius: 4px; padding: .05em .3em; overflow-wrap: anywhere;
}
/* A \texttt{} run glued to the surrounding word (C++23, .fx) must not be boxed. */
.cna-tt-joined, .cna-tt-joined .ltx_font_typewriter,
.ltx_listing .ltx_font_typewriter {
  background: none !important; border: 0 !important; padding: 0 !important;
}
.ltx_font_bold { font-weight: 700; }
.ltx_font_italic, .ltx_emph { font-style: italic; }
.ltx_font_serif { font-family: var(--serif); }

.ltx_itemize, .ltx_enumerate, .ltx_description {
  list-style: none; margin: 0 0 1.15rem; padding-left: 1.6rem;
}
.ltx_item { position: relative; margin-bottom: .5rem; }
.ltx_item > .ltx_tag {
  position: absolute; left: -1.6rem; width: 1.35rem;
  text-align: right; color: var(--fg-faint); font-size: .9em;
}
.ltx_description > .ltx_item > .ltx_tag {
  position: static; display: block; width: auto; text-align: left;
  font-family: var(--sans); font-weight: 700; color: var(--fg);
}
.ltx_description { padding-left: 0; }

/* ------------------------------------------------------------------- notes */
.cna-note {
  margin: 1.6rem 0; padding: 1rem 1.15rem;
  border: 1px solid var(--rule); border-left: 4px solid var(--rule-strong);
  border-radius: 6px; background: var(--bg-raised);
}
.cna-note > :last-child { margin-bottom: 0; }
.cna-note-source     { background: var(--note-source-bg);     border-left-color: var(--note-source-line); }
.cna-note-contract   { background: var(--note-contract-bg);   border-left-color: var(--note-contract-line); }
.cna-note-evidence   { background: var(--note-evidence-bg);   border-left-color: var(--note-evidence-line); }
.cna-note-history    { background: var(--note-history-bg);    border-left-color: var(--note-history-line); }
.cna-note-limitation { background: var(--note-limitation-bg); border-left-color: var(--note-limitation-line); }
.cna-note .ltx_font_typewriter { background: color-mix(in srgb, var(--bg-raised) 60%, transparent); }

.ltx_quote { margin: 1.5rem 0; padding-left: 1.2rem; border-left: 3px solid var(--rule-strong);
  color: var(--fg-muted); font-style: italic; }

/* ------------------------------------------------------------------ tables */
.ltx_table, .ltx_tabular { margin: 0; }
.ltx_table { margin: 1.8rem 0; }
.cna-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.ltx_tabular {
  border-collapse: collapse; width: 100%;
  font-family: var(--sans); font-size: .84rem; line-height: 1.5;
}
table.ltx_tabular .ltx_td, table.ltx_tabular .ltx_th {
  padding: .45rem .7rem; vertical-align: top; text-align: left;
}
table.ltx_tabular .ltx_th { font-weight: 700; }
.ltx_border_t  { border-top: 1px solid var(--rule); }
.ltx_border_tt { border-top: 2px solid var(--rule-strong); }
.ltx_border_b  { border-bottom: 1px solid var(--rule); }
.ltx_border_bb { border-bottom: 2px solid var(--rule-strong); }
.ltx_border_r  { border-right: 1px solid var(--rule); }
.ltx_border_l  { border-left: 1px solid var(--rule); }
table.ltx_tabular tbody tr:nth-child(even) { background: var(--bg-sunken); }
.ltx_align_right { text-align: right; }
.ltx_align_center, .ltx_centering { text-align: center; }
.ltx_align_justify { text-align: left; }
.ltx_inline-block { display: inline-block; }
.ltx_inline-block .ltx_p { margin: 0; }

/* ----------------------------------------------------------------- figures */
figure.ltx_figure, figure.ltx_table {
  margin: 2rem 0; padding: 1rem; text-align: center;
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 8px;
}
figure.ltx_figure img { max-width: 100%; height: auto; background: #fff;
  border-radius: 4px; padding: .5rem; }
figcaption.ltx_caption {
  margin-top: .9rem; font-family: var(--sans); font-size: .82rem;
  line-height: 1.55; color: var(--fg-muted); text-align: left;
}
figcaption.ltx_caption .ltx_tag { font-weight: 700; color: var(--fg); }

/* ---------------------------------------------------------------- listings */
.ltx_listing {
  position: relative;
  margin: 1.5rem 0; padding: .85rem 0;
  background: var(--bg-code) !important;
  border: 1px solid var(--rule) !important;
  border-radius: 8px;
  font-family: var(--mono); font-size: .8rem; line-height: 1.6;
  overflow-x: auto;
}
.ltx_listingline { display: block; white-space: pre; padding: 0 1rem 0 0; }
.ltx_listingline > .ltx_tag_listingline {
  display: inline-block; width: 2.8rem; padding-right: .9rem;
  text-align: right; color: var(--fg-faint); user-select: none;
}
.ltx_listing .ltx_font_typewriter { background: none; border: 0; padding: 0; font-size: 1em; }
.ltx_lst_keyword  { color: #0a5b90; font-weight: 600; }
.ltx_lst_comment  { color: #7a7a7a; font-style: italic; }
.ltx_lst_string   { color: #8c1414; }
:root[data-theme="dark"] .ltx_lst_keyword { color: #7fc0ea; }
:root[data-theme="dark"] .ltx_lst_comment { color: #8d9199; }
:root[data-theme="dark"] .ltx_lst_string  { color: #e2a08a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ltx_lst_keyword { color: #7fc0ea; }
  :root:not([data-theme="light"]) .ltx_lst_comment { color: #8d9199; }
  :root:not([data-theme="light"]) .ltx_lst_string  { color: #e2a08a; }
}
.ltx_listing_data { position: absolute; top: .4rem; right: .4rem; }
a.cna-copy {
  font-family: var(--sans); font-size: .7rem; letter-spacing: .04em;
  padding: .2rem .5rem; border: 1px solid var(--rule-strong); border-radius: 4px;
  color: var(--fg-muted); background: var(--bg-raised); text-decoration: none;
  opacity: 0; transition: opacity .15s;
}
.ltx_listing:hover a.cna-copy, a.cna-copy:focus { opacity: 1; }
a.cna-copy:hover { color: var(--fg); border-color: var(--accent); }

pre.ltx_verbatim {
  margin: 1.5rem 0; padding: .9rem 1rem; overflow-x: auto;
  background: var(--bg-code); border: 1px solid var(--rule); border-radius: 8px;
  font-family: var(--mono); font-size: .8rem; line-height: 1.6;
}

/* ------------------------------------------------------------------- math */
.ltx_Math { font-size: 1em; }
math { font-size: 1em; }

/* ------------------------------------------------------------- refs & index */
a.ltx_ref { text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 40%, transparent); }
a.ltx_ref:hover { border-bottom-color: var(--link); }
a.cna-dead { color: var(--fg-muted); border-bottom: 1px dotted var(--fg-faint); }

.ltx_indexlist { list-style: none; margin: 0; padding: 0;
  columns: 2; column-gap: 2.5rem; font-family: var(--sans); font-size: .84rem; }
.ltx_indexentry { break-inside: avoid; margin-bottom: .35rem; }
.ltx_indexphrase { color: var(--fg); }
.ltx_indexrefs { color: var(--fg-muted); }
.ltx_indexlist .ltx_indexlist { columns: 1; padding-left: 1rem; }
@media (max-width: 60rem) { .ltx_indexlist { columns: 1; } }

/* -------------------------------------------------------------- home page */
.cna-cover {
  text-align: center; padding: 2.5rem 1.5rem 3rem; margin-bottom: 2.5rem;
  border: 1px solid var(--rule); border-radius: 12px; background: var(--bg-raised);
}
.cna-cover .ltx_p { margin-bottom: .9rem; }
.cna-contents h2 { font-family: var(--sans); font-size: 1.35rem; margin-bottom: 1rem; }
.cna-contents-list, .cna-contents-chapters { list-style: none; margin: 0; padding: 0; }
.cna-contents-list > li { margin-bottom: .3rem; }
.cna-contents-part > a {
  display: block; margin-top: 1.6rem; padding-bottom: .3rem;
  font-family: var(--sans); font-size: .8rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg); text-decoration: none; border-bottom: 1px solid var(--rule);
}
.cna-contents-part > a:hover { color: var(--accent); }
.cna-contents-chapters { margin: .5rem 0 0; }
.cna-contents-chapters li a, .cna-contents-appendix a, .cna-contents-front a {
  display: flex; gap: .75rem; padding: .25rem .4rem; border-radius: 4px;
  font-family: var(--sans); font-size: .92rem; text-decoration: none; color: var(--fg);
}
.cna-contents-chapters li a:hover, .cna-contents-appendix a:hover,
.cna-contents-front a:hover { background: var(--bg-sunken); color: var(--accent); }
.cna-contents-chapters .cna-num, .cna-contents-appendix .cna-num { min-width: 2.4rem; }

/* ----------------------------------------------------------------- search */
dialog.cna-search {
  width: min(46rem, 92vw); max-height: 80vh; padding: 0;
  border: 1px solid var(--rule-strong); border-radius: 12px;
  background: var(--bg-raised); color: var(--fg);
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
dialog.cna-search::backdrop { background: rgba(0,0,0,.45); }
.cna-search-form { display: flex; gap: .5rem; padding: 1rem; border-bottom: 1px solid var(--rule); }
#cna-search-input {
  flex: 1; font: inherit; font-family: var(--sans); font-size: 1rem;
  padding: .55rem .8rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--rule-strong); border-radius: 6px;
}
.cna-search-close {
  font-family: var(--sans); font-size: .75rem; padding: .3rem .6rem;
  color: var(--fg-muted); background: transparent;
  border: 1px solid var(--rule-strong); border-radius: 5px; cursor: pointer;
}
.cna-search-hint { margin: 0; padding: .6rem 1rem; font-family: var(--sans);
  font-size: .78rem; color: var(--fg-faint); }
.cna-search-results {
  list-style: none; margin: 0; padding: 0 1rem 1rem;
  overflow-y: auto; max-height: calc(80vh - 8rem);
}
.cna-search-results li { border-top: 1px solid var(--rule); }
.cna-search-results a {
  display: block; padding: .7rem .4rem; text-decoration: none; color: var(--fg);
  font-family: var(--sans);
}
.cna-search-results a:hover, .cna-search-results a:focus { background: var(--bg-sunken); }
.cna-result-title { display: block; font-size: .92rem; font-weight: 600; }
.cna-result-crumb { display: block; font-size: .74rem; color: var(--fg-faint); }
.cna-result-snippet { font-size: .82rem; color: var(--fg-muted); line-height: 1.5; margin-top: .2rem; }
.cna-result-snippet mark { background: var(--accent-soft); color: var(--fg); border-radius: 2px; }

/* ----------------------------------------------------------------- footer */
.cna-footer {
  border-top: 1px solid var(--rule); margin-top: 2rem; padding: 1.75rem 2rem 3rem;
  font-family: var(--sans); font-size: .8rem; color: var(--fg-muted); text-align: center;
}
.cna-footer p { margin: .2rem 0; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 80rem) {
  .cna-shell { grid-template-columns: var(--rail) minmax(0, 1fr); }
  .cna-onpage { display: none; }
  .cna-main { padding-inline: 2rem; }
}
@media (max-width: 60rem) {
  .cna-shell { grid-template-columns: minmax(0, 1fr); }
  .cna-menu { display: inline-flex; }
  .cna-sidebar {
    display: none;
    position: fixed; inset: var(--header-h) auto 0 0; z-index: 35;
    width: min(21rem, 86vw); background: var(--bg-raised);
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  .cna-sidebar.is-open { display: block; }
  /* An outsized shadow dims the page behind the open drawer without needing a
     separate scrim element. */
  .cna-sidebar.is-open { box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  .cna-main { padding: 1rem 1.15rem 3rem; }
  .cna-btn-text { display: none; }
  .cna-pager { flex-direction: column; }
}

/* --------------------------------------------------------------- printing */
@media print {
  .cna-header, .cna-sidebar, .cna-onpage, .cna-pager, .cna-breadcrumb,
  .cna-footer, dialog.cna-search { display: none !important; }
  .cna-shell { display: block; }
  .cna-main { padding: 0; }
  .cna-article { max-width: none; }
  body { font-size: 11pt; }
  .ltx_listing, figure { break-inside: avoid; }
}
