/* R-174, site styles from Keep the Life: pretty wrap, the reading column and the contents. */
/* pretty wrap: native where supported, the script fills in elsewhere.
   pw-js is set on :root when the script detects that native pretty is too
   weak (e.g. Firefox) and takes over; the CSS property is then turned off
   so the browser's partial implementation does not fight the script. */
.pretty * {
  text-wrap-style: pretty;
}
.pw-js .pretty * {
  text-wrap-style: auto;
}
/* the entries of the contents are short, so their lines are balanced, and
   a two-line entry never ends on a lone word */
.pretty .toc a,
.pretty .news-head {
  text-wrap-style: balance;
}
/* layout: the reading column is centred when the window allows. On wide
   screens the contents take a fixed slot in the left margin. When the column
   is wider than the room left by that slot, it grows to the right. Hiding the
   contents frees the slot, so a column that was held back by it expands.
   Full width uses everything: beside the contents when they are shown, the
   whole window when they are hidden. */
.layout {
  --toc-w: 15rem;
  --toc-space: calc(var(--toc-w) + var(--s) * 2);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding: 0 var(--gutter);
}
.story {
  width: var(--l-100pct);
  max-width: var(--page-max);
  margin-inline: auto;
}
@media (min-width: 1200px) {
  .layout {
    grid-template-columns: max(var(--toc-space), (var(--l-100pct) - var(--page-max)) / 2) minmax(
        0,
        var(--page-max)
      ) minmax(0, 1fr);
  }
  .toc {
    grid-column: 1;
    grid-row: 1;
    width: var(--toc-w);
    justify-self: end;
    margin-right: calc(var(--s) * 2);
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow: auto;
  }
  .story {
    grid-column: 2;
    grid-row: 1;
    max-width: none;
  }
  .width-full .layout {
    grid-template-columns: var(--toc-space) minmax(0, 1fr) 0;
  }
  /* without the contents the column is free to use the left margin too */
.no-toc .layout {
    grid-template-columns: max(var(--l-0px), (var(--l-100pct) - var(--page-max)) / 2) minmax(
        0,
        var(--page-max)
      ) minmax(0, 1fr);
  }
  .width-full .no-toc .layout {
    grid-template-columns: 0 minmax(0, 1fr) 0;
  }
}
.no-toc .toc {
  display: none;
}
/* below the wide layout the contents leave the page and open as a floating
   menu from the dock (css/site/dock.css, js/reading/tocmenu.js); without
   scripts they stay in the page as a plain list */
@media (max-width: 1199px) {
  html:not(.no-js) .toc {
    display: none;
  }
  html:not(.no-js) .toc-open .toc {
    display: block;
    position: fixed;
    z-index: 29;
    left: var(--s);
    right: var(--s);
    bottom: calc(var(--s) * 4);
    max-width: 17rem;
    max-height: min(70vh, 36rem);
    margin-left: auto;
    overflow: auto;
    padding: var(--s);
    background: var(--bg-2);
    border: var(--l-1px) solid var(--rule-2);
    box-shadow: 0 var(--l-8px) var(--l-24px) var(--shadow);
  }
  /* the floating menu has its own background, so the edge fade would only
     let the page show through it */
html:not(.no-js) .toc-open .toc {
    -webkit-mask-image: none;
    mask-image: none;
  }
  /* with the contents hidden, the Settings button stays in the dock */
.no-toc .toc-fab {
    display: none !important;
  }
}
/* the contents and the highlights and notes panel scroll on their own with
   no scrollbar; a fade at the top or bottom edge shows there is more to
   scroll in that direction */
.toc {
  scrollbar-width: none;
}
.toc::-webkit-scrollbar {
  display: none;
}
.fade-top,
.fade-bottom {
  --fade-top: 0px;
  --fade-bottom: 0px;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent,
    var(--c-000) var(--fade-top),
    var(--c-000) calc(var(--l-100pct) - var(--fade-bottom)),
    transparent
  );
  mask-image: linear-gradient(
    to bottom,
    transparent,
    var(--c-000) var(--fade-top),
    var(--c-000) calc(var(--l-100pct) - var(--fade-bottom)),
    transparent
  );
}
.fade-top {
  --fade-top: 3rem;
}
.fade-bottom {
  --fade-bottom: 3rem;
}
/* contents */
.toc {
  padding: var(--s) 0;
  font-size: var(--l-0-9rem);
}
.toc h2 {
  margin: 0 0 var(--l-0-5rem);
  font: 600 var(--l-0-72rem) var(--mono);
  letter-spacing: var(--l-0-2em);
  text-transform: uppercase;
  color: var(--mute);
}
.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc-ch + .toc-ch {
  margin-top: var(--s);
}
.toc-ch ol {
  margin-top: var(--l-0-25rem);
  border-left: var(--l-1px) solid var(--rule);
}
.toc a {
  display: flex;
  gap: var(--l-0-6rem);
  text-decoration: none;
  color: var(--ink-2);
  padding: var(--l-0-2rem) 0 var(--l-0-2rem) var(--l-0-75rem);
  margin-left: -1px;
  border-left: var(--l-2px) solid transparent;
  line-height: 1.35;
}
.toc a:hover {
  color: var(--ink);
}
.toc a.on {
  color: var(--ink);
  border-left-color: var(--sp-k);
}
.toc .toc-cht {
  padding-left: 0;
  border: 0;
  font-weight: 600;
  color: var(--ink);
}
.toc-n {
  font: 500 var(--l-0-75rem) / 1.6 var(--mono);
  color: var(--mute);
  min-width: var(--l-1-9rem);
}
/* the heading row: Contents on the left, a quiet Show keys button on the
   right that opens the key list under it */
.toc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s);
  margin-bottom: var(--s);
}
/* with the key list open, the list carries the space above the chapters in
   its own bottom padding, which matches the margin used while it is hidden */
@media (min-width: 1200px) {
  html:not(.no-js) body.keys .toc-head:has(+ .toc-keys:not([hidden])) {
    margin-bottom: var(--l-0-5rem);
  }
}
.toc-head h2 {
  margin: 0;
}
.toc-keys-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--l-0-2rem);
  font: 500 var(--l-0-72rem) var(--mono);
  letter-spacing: var(--l-0-2em);
  text-transform: uppercase;
  color: var(--mute);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.toc-keys-btn:hover {
  color: var(--ink);
}
.toc-keys-btn .ico {
  width: var(--l-12px);
  height: var(--l-12px);
  transition: transform 0.15s;
}
/* the arrow points up while the list is open */
.toc-keys-btn[aria-expanded="true"] .ico {
  transform: rotate(180deg);
}
.toc-keys {
  margin: 0;
  padding-bottom: var(--s);
  color: var(--mute);
  font-size: var(--l-0-78rem);
}
@media (max-width: 1199px) {
  .toc {
    border-bottom: var(--l-1px) solid var(--rule);
  }
  .toc-keys,
  .toc-keys-btn {
    display: none;
  }
}
/* with the keys switched off there is nothing to list */
body:not(.keys) .toc-keys,
body:not(.keys) .toc-keys-btn {
  display: none;
}
