/* THE CHAPTER RAIL : a quiet way through a long room (H5, 2026-10-03).
   It telleth the reader where they stand, letteth them jump to any host or
   chapter, and giveth a way back to the index; it is dismissible.

   HOW IT KEEPETH OFF THE TEXT: it is not a floating slab. The rail liveth
   INSIDE the room's own sticky header — the same band the house already
   carrieth on every page, and the same band every jump already clear via
   scroll-margin-top. So it covereth no text that the header did not already
   cover, it addeth no new layer over the reading, and a jump landeth clear
   beneath the band. To keep the band from growing without bound it showeth
   ONE line: where the reader standeth, and the few words needed to move.

   In print it is not shown.
   TEMPLE MARK R2: ␛ : chapter-rail.css */

.chapter-rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem var(--space-2);
  width: 100%;
  margin: 0.15rem 0 0;
  padding: 0.15rem 0 0;
  border-top: 1px solid var(--line-dark);
  font: 500 0.75rem/1.35 var(--font-ui);
  color: var(--ink);
}

.chapter-rail-now {
  flex: 1 1 10rem;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--bureau);
  font-variant-numeric: tabular-nums;
}

.chapter-rail-toggle,
.chapter-rail-back,
.chapter-rail-hide {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.2rem 0.6rem;
  border: 1px solid transparent;
  border-radius: var(--radius-pill, 999px);
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.chapter-rail-toggle { color: var(--brass); }
.chapter-rail-toggle:hover,
.chapter-rail-toggle:focus-visible,
.chapter-rail-back:hover,
.chapter-rail-back:focus-visible,
.chapter-rail-hide:hover,
.chapter-rail-hide:focus-visible {
  background: rgba(212, 175, 55, 0.12);
  text-decoration: none;
}

.chapter-rail-hide { color: var(--bureau); }

/* The list openeth as an ordinary row in the SAME band: the band groweth by a
   bounded amount (it never exceedeth 44vh) and then scrolleth within itself.
   When it is closed the band returneth to its one line. */
.chapter-rail-list {
  flex: 1 1 100%;
  margin: 0.2rem 0 0;
  padding: 0;
  border-top: 1px solid var(--line-dark);
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0 var(--space-2);
  max-height: 44vh;
  overflow-y: auto;
}

.chapter-rail-list[hidden] { display: none; }

.chapter-rail-list a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0.3rem var(--space-2);
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm, 6px);
}

.chapter-rail-list a:hover,
.chapter-rail-list a:focus-visible {
  background: rgba(212, 175, 55, 0.12);
  text-decoration: none;
}

/* The house's jump margin must account for the band the rail inhabiteth. */
body.has-chapter-rail :where([id]) { scroll-margin-top: 8.5rem; }

/* THE MAIN LANDMARK'S OWN CLEARANCE (MF-026, 2026-10-08). The banner now
   standeth before main, so a landing on #main (the skip link's target, and
   any deep link to the room's head) must clear the sticky band the same way
   every in-page target doth. */
body.site-page[data-room-family] #main { scroll-margin-top: var(--band-clear, 8.5rem); }

/* THE RAIL'S LINE IS THE BAND'S SECOND LINE (MF-025, 2026-10-08). Where the
   fold standeth (phones), the rail carrieth only where the reader standeth:
   its pills stand in the disclosure, and the line never grows the band. */
@media (max-width: 48rem) {
  body[data-room-family] .room-header.has-ways .chapter-rail {
    margin-top: 0.1rem;
    padding-block: 0.1rem;
    gap: 0;
  }
  body[data-room-family] .room-header.has-ways .chapter-rail-now {
    font-size: 0.75rem;
    line-height: 1.35;
  }
}

/* THE REGISTER ROOMS' TRUE CLEARANCE (task 289, 2026-10-03). The band of a
   chapter or the Register is tall at the narrow widths (about 500px on a
   phone, the rail included), and a fragment landing must clear the band that
   IS. Where script runneth, the rail setteth --band-clear from the MEASURED
   band (at every width, and again on resize, whether the rail is shown or
   dismissed); where it runneth not, the fallback 8.5rem cleareth the
   scriptless band (measured 114px at 390px, 71px at 1440px).
   Scoped to the heavenly rooms, which are the register family. */
body.heavenly :where([id]) { scroll-margin-top: var(--band-clear, 8.5rem); }

@media (prefers-reduced-motion: reduce) {
  .chapter-rail a { transition: none; }
}

/* Paper carrieth the room, not the rail. */
@media print {
  .chapter-rail { display: none !important; }
}
