/* The right column of the reading pages (module.php): on design.css's lv-rail and lv-toc, which are a generated copy of
   the design. Hook lv-rail--stick is the column that sticks, lv-rail--end the cards moved to the end of the article. */

/* ---------- The list: a card like the rail's others, plain links at the size of the text they point to ---------- */
.lv-rail .lv-toc { --pad: 28px; --gutter-n: 1.95em; border: 1px solid var(--c-hairline); border-radius: var(--radius-card); padding: 0; background: var(--c-paper); overflow: hidden; }
.lv-rail .lv-toc:not(:has(li:nth-child(10))) { --gutter-n: 1.2em; } /* under 10 lines the numbers sit under the label */
.lv-rail .lv-toc .lbl { display: none; font-size: var(--fs-body); line-height: 1.3; margin: 0; padding: 24px var(--pad) 0; }
.lv-rail .lv-toc ol { padding: 0 var(--pad) 12px calc(var(--pad) + var(--gutter-n)); margin: 0; scrollbar-width: thin; scrollbar-color: var(--c-edge) transparent; }
.lv-rail .lv-toc li { padding: 0; font-size: var(--fs-body); line-height: 1.4; }
.lv-rail .lv-toc li::marker { color: var(--c-head); font-variant-numeric: tabular-nums; }
/* Not design.css's rail link: no rule under each line. One line is a 48px target, and every row has the same 20px between
   its text and the next, so one and two line rows keep one rhythm and a long heading wraps evenly inside its target */
.lv-rail .lv-toc li a { display: block; min-height: 0; padding: 10px 0; border-bottom: 0; font-size: inherit; line-height: inherit; overflow-wrap: break-word; text-wrap: balance; }
/* The section being read: the underline a hovered link has (frame/style.css takes it off at rest), and nothing else */
.lv-rail .lv-toc a[aria-current="location"] { text-decoration-line: underline; text-decoration-thickness: 3px; text-underline-offset: 4px; }

/* The tap to open: the card's whole first row, with a chevron that turns */
.lv-rail .lv-toc summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; padding: 12px var(--pad); list-style: none; cursor: pointer; font-weight: 700; color: var(--c-head); }
.lv-rail .lv-toc summary::-webkit-details-marker { display: none; }
.lv-rail .lv-toc summary::after { content: ""; flex: none; width: 12px; height: 12px; margin: -6px 4px 0 0; border: solid currentColor; border-width: 0 3px 3px 0; transform: rotate(45deg); }
.lv-rail .lv-toc details[open] > summary::after { margin-top: 6px; transform: rotate(225deg); }
.lv-rail .lv-toc summary:hover { text-decoration: underline 3px; text-underline-offset: 4px; }
.lv-rail .lv-toc summary:focus-visible { outline-offset: -5px; box-shadow: none; }

/* Desktop and print: always open with a plain label. Where ::details-content is missing (Safari before 18.4) rail.js
   opens it; with no script there either the summary stays, so the list is a tap away rather than lost */
@supports selector(::details-content) {
  @media print, (min-width: 1101px) {
    .lv-rail .lv-toc .lbl { display: block; }
    .lv-rail .lv-toc summary { display: none; }
    .lv-rail .lv-toc details::details-content { content-visibility: visible; }
  }
}

/* ---------- The cards: two line rows keep their air, the cards' type is the list's ---------- */
:is(.lv-rail--stick, .lv-rail--end) li a { padding-block: 10px; font-size: var(--fs-body); line-height: 1.4; }
.lv-rail--end h2 { font-size: var(--fs-h3); margin-bottom: 12px; }

/* ---------- Device pages: the bands keep their full-width color, their text keeps out of the column ---------- */
.lv-aid-bands h2 { scroll-margin-top: 24px; }

/* ---------- One column: the list heads the article, not sticky, the phone card under it ---------- */
@media (max-width: 1100px) {
  .lv-art .lv-rail--stick, .lv-art .lv-rail--end, .lv-aid-railwrap .lv-rail--stick { grid-template-columns: minmax(0, 1fr); max-width: 34em; }
  .lv-art .grid:has(> .lv-rail--stick) { row-gap: 48px; }
  .lv-aid-railwrap { padding-top: 48px; }
}

/* ---------- Two columns: the rail runs down the second track, beside every row of the first ---------- */
@media (min-width: 1101px) {
  /* Wider than design.css's 360px: the text keeps its 34em, so this only takes from the gap beside it, and fewer lines wrap */
  .lv-art .grid:has(> .lv-rail--stick) { grid-template-columns: minmax(0, 1fr) clamp(320px, 30vw, 440px); grid-template-rows: auto auto auto 1fr; row-gap: 0; }
  .lv-art .grid > .lv-rail--stick { grid-column: 2; grid-row: 1 / -1; }
  .lv-art .grid:has(> .lv-rail--stick) > :not(.lv-rail--stick) { grid-column: 1; }
  .lv-art .lv-rail--stick + .lv-prose > :first-child { margin-top: 0; }
  .lv-rail--end { grid-template-columns: minmax(0, 1fr); margin-top: 72px; max-width: 34em; }
  .lg-rail.lv-rail--end .lg-back { display: none; } /* the list is in view all the way down */

  .lv-aid-body { display: grid; grid-template-columns: minmax(0, 1fr); }
  .lv-aid-body > * { grid-area: 1 / 1; min-width: 0; }
  .lv-aid-railwrap { width: 100%; pointer-events: none; z-index: 1; }
  .lv-aid-railwrap .lv-rail { width: 360px; margin: 72px 0 72px auto; pointer-events: auto; }
  .lv-aid-bands .wrap { padding-right: calc(var(--gutter) + 360px + 96px); }
  /* That leaves the width of the article's column: a band's two tracks stack, as they do on a tablet */
  .lv-aid-bands .grid { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .lv-aid-bands .lv-related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Sticks on any screen with room for the list and the card under it; the list takes what the card leaves and scrolls */
@media (min-width: 1101px) and (min-height: 520px) {
  .lv-rail--stick { display: flex; flex-direction: column; gap: 24px; position: sticky; top: 24px; max-height: calc(100vh - 48px); }
  .lv-rail--stick:not(:has(.lv-toc)) { overflow-y: auto; }
  .lv-rail--stick > * { flex: none; }
  .lv-rail--stick > .lv-toc, .lv-rail--stick .lv-toc details, .lv-rail--stick .lv-toc details::details-content { display: flex; flex-direction: column; min-height: 0; }
  .lv-rail--stick > .lv-toc { flex: 0 1 auto; }
  .lv-rail--stick .lv-toc ol { min-height: 0; padding-bottom: 0; overflow-y: auto; }
  /* A line cut by the edge of a scrolling list fades out. Each fade holds its own space at the ends of the list */
  .lv-rail--stick .lv-toc ol::before, .lv-rail--stick .lv-toc ol::after { content: ""; display: block; position: sticky; z-index: 1; height: 32px; margin-left: calc(-1 * (var(--pad) + var(--gutter-n))); margin-right: calc(-1 * var(--pad)); pointer-events: none; }
  .lv-rail--stick .lv-toc ol::before { top: 0; margin-bottom: -20px; background: linear-gradient(var(--c-paper) 25%, transparent); }
  .lv-rail--stick .lv-toc ol::after { bottom: 0; margin-top: -20px; background: linear-gradient(transparent, var(--c-paper) 75%); }
  @supports not selector(::details-content) { .lv-rail--stick { overflow-y: auto; } }
}
@media (forced-colors: active) { .lv-rail .lv-toc { border-color: CanvasText; } }
