/* manual.css — skin for the flashalign(1) manual as produced by
 *     mandoc -Thtml -O style=manual.css flashalign.1
 * (docs/mkmanual.py runs that and adds the <nav class="toc"> contents list).
 *
 * It only styles the class names mandoc emits (.head, .manual-text, .Sh, .Ss,
 * .Bl-tag, .Bd-indent, .tbl, .foot ...), so re-running mandoc on a new
 * flashalign.1 keeps the look. Works with mandoc 1.14.x (<table class="head">,
 * <h1 class="Sh">) and newer mandoc (<div class="head">, <h2 class="Sh">).
 *
 * Layout: header bar / sticky contents sidebar + manual text / footer bar.
 * Dark mode follows the reader's system setting. No JavaScript.
 */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f9fb;
  --bg-code: #f3f5f7;
  --text: #1b1f24;
  --muted: #5c6670;
  --faint: #b3bcc6;
  --rule: #e3e8ee;
  --accent: #0b5fb0;
  --accent-strong: #083f75;
  --toc-current: #eaf1fb;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar: 248px;
  --measure: 76ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --bg-soft: #161a20;
    --bg-code: #1a1f26;
    --text: #e6e9ed;
    --muted: #9aa5b1;
    --faint: #58626d;
    --rule: #2a313a;
    --accent: #6cb0f0;
    --accent-strong: #9ccbf7;
    --toc-current: #1d2a3a;
  }
}

/* ---------- page ---------- */

html {
  scroll-padding-top: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: 1240px;
  padding: 0 32px;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  column-gap: 48px;
  min-height: 100vh;
}

/* No contents list (plain mandoc output without mkmanual.py): one column. */
body:not(:has(nav.toc)) {
  grid-template-columns: minmax(0, 1fr);
}
body:not(:has(nav.toc)) .manual-text {
  grid-column: 1;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

b, strong {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.93em;
}

i, em {
  font-style: italic;
}

code, pre, kbd {
  font-family: var(--mono);
}

/* ---------- header bar (table.head in 1.14.x, div.head in newer mandoc) ---------- */

.head, .foot {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 24px;
  margin: 0 -32px;
  padding: 12px 32px;
  font-size: 14px;
  color: var(--muted);
}
.head {
  grid-row: 1;
  border-bottom: 1px solid var(--rule);
  background: var(--bg-soft);
}
.foot {
  grid-row: 3;
  border-top: 1px solid var(--rule);
  margin-top: 48px;
  font-size: 13px;
}
/* flatten the table version so the cells become flex items */
table.head, table.foot { width: auto; border-collapse: collapse; }
table.head tbody, table.foot tbody, table.head tr, table.foot tr { display: contents; }
.head td, .foot td { display: block; padding: 0; }

.head-ltitle {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.head-vol {
  text-align: center;
}
.head-rtitle, .foot-right {
  text-align: right;
  font-family: var(--mono);
}
.foot-left, .foot-os {
  font-family: var(--mono);
}
.foot-date, .foot-os {
  text-align: left;
}

/* ---------- contents sidebar (inserted by mkmanual.py) ---------- */

nav.toc {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 36px 0 24px;
  box-sizing: border-box;
}
nav.toc .toc-title {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 5px 10px 10px;
}
nav.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
nav.toc a {
  display: block;
  padding: 5px 10px;
  border-radius: 5px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}
nav.toc a:hover {
  background: var(--bg-code);
  text-decoration: none;
}
nav.toc ul ul a {
  padding-left: 22px;
  font-size: 13.5px;
  color: var(--muted);
}
nav.toc ul ul a:hover {
  color: var(--text);
}

/* ---------- manual text ---------- */

.manual-text {
  grid-column: 2;
  grid-row: 2;
  max-width: var(--measure);
  min-width: 0;
  padding: 36px 0 0;
}

section.Sh {
  margin: 0 0 36px;
  scroll-margin-top: 16px;
}

/* NAME, SYNOPSIS, ... : small spaced caps with a rule, man-page flavour */
.Sh:is(h1, h2, h3) {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.25;
  margin: 0 0 16px;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--rule);
}

/* Indexing options, Placement options, ... */
.Ss:is(h2, h3, h4) {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  margin: 26px 0 10px;
  scroll-margin-top: 16px;
}

/* heading permalinks: same colour as the heading, a # appears on hover */
.Sh a.permalink, .Ss a.permalink {
  color: inherit;
}
.Sh a.permalink:hover, .Ss a.permalink:hover,
dl.Bl-tag > dt > a.permalink:hover {
  text-decoration: none;
}
.Sh a.permalink:hover::after, .Ss a.permalink:hover::after,
dl.Bl-tag > dt > a.permalink:hover::after {
  content: " #";
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: 0;
}

p.Pp {
  margin: 0 0 14px;
}
p.Pp:empty {
  display: none;
}

/* ---------- synopsis: each indented block becomes a code block ---------- */

section.Sh:has(> .Sh#SYNOPSIS) p.Pp {
  font-size: 13.5px;
  color: var(--muted);
  margin: 14px 0 6px;
}
section.Sh:has(> .Sh#SYNOPSIS) .Bd-indent {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg-code);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 0;
  overflow-wrap: anywhere;
}
section.Sh:has(> .Sh#SYNOPSIS) .Bd-indent b {
  font-size: inherit;
  font-weight: 700;
}

/* other indented blocks (the preset list under Preset options) */
.Bd-indent {
  margin: 0 0 14px 24px;
}

/* ---------- options: hanging list ---------- */

dl.Bl-tag {
  margin: 0;
}
dl.Bl-tag > dt {
  margin: 18px 0 4px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.4;
  scroll-margin-top: 16px;
}
dl.Bl-tag > dt b {
  font-size: inherit;
  font-weight: 700;
}
dl.Bl-tag > dt i {
  font-weight: 400;
  color: var(--muted);
}
dl.Bl-tag > dt > a.permalink {
  color: inherit;
}
dl.Bl-tag > dd {
  margin: 0 0 0 24px;
}
dl.Bl-tag > dd > dl.Bl-tag {
  margin-left: 0;
}

/* ---------- tables (PAF columns, tags, cs operations) ---------- */

table.tbl {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  border: 1px solid var(--rule) !important;
  border-radius: 6px;
  margin: 4px 0 16px;
  font-size: 14.5px;
}
table.tbl tr {
  border: 0 !important;
}
table.tbl td {
  padding: 8px 12px;
  border: 0 !important;
  border-bottom: 1px solid var(--rule) !important;
  vertical-align: top;
}
table.tbl tr:last-child td {
  border-bottom: 0 !important;
}
table.tbl tr:first-child td {
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left !important;
}
table.tbl tr:first-child td b {
  font-family: var(--sans);
  font-size: inherit;
  font-weight: 600;
}
table.tbl tr:not(:first-child) td:first-child,
table.tbl tr:not(:first-child) td:nth-child(2) {
  font-family: var(--mono);
  font-size: 13.5px;
  white-space: nowrap;
  color: var(--muted);
}

/* ---------- phone / narrow window ---------- */

@media (max-width: 880px) {
  body {
    display: block;
    padding: 0 16px;
  }
  .head, .foot {
    margin: 0 -16px;
    padding: 12px 16px;
  }
  .head-rtitle {
    display: none;
  }
  nav.toc {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 20px 0 0;
    border-bottom: 1px solid var(--rule);
  }
  nav.toc .toc-title {
    padding: 0 0 8px;
  }
  nav.toc ul {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 16px;
  }
  nav.toc li, nav.toc ul ul {
    display: contents;
  }
  nav.toc a, nav.toc ul ul a {
    padding: 8px 12px;
    min-height: 44px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--bg-soft);
    color: var(--text);
    font-size: 14px;
  }
  .manual-text {
    padding-top: 24px;
  }
  dl.Bl-tag > dd {
    margin-left: 16px;
  }
}

/* ---------- print ---------- */

@media print {
  body {
    display: block;
    max-width: none;
    padding: 0;
    font-size: 11pt;
  }
  nav.toc {
    display: none;
  }
  .head, .foot {
    margin: 0;
    background: none;
  }
  a {
    color: inherit;
  }
}
