/* Leslie House contents spine.
   One native <details> replaces the former always-open chapter list and the
   duplicate decorative progress rail. The summary remains useful without JS. */

.rail {
  position: fixed;
  z-index: 29;
  left: clamp(.5rem, 1.25vw, 1.15rem);
  top: 50%;
  margin: 0;
  transform: translateY(-50%);
  color: var(--ink);
}

.rail__summary {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.1rem;
  width: 44px;
  min-height: clamp(10rem, 25vh, 14rem);
  padding: .85rem .65rem;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ink) 22%, transparent);
  background: rgba(250, 248, 244, .97);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: max(.75rem, var(--text-label));
  font-weight: 600;
  line-height: 1;
  letter-spacing: .15em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transition: border-color var(--dur-fast, 150ms) linear,
              background-color var(--dur-fast, 150ms) linear;
}

.rail__summary::-webkit-details-marker { display: none; }
.rail__summary::marker { content: ""; }

.rail__summary::after {
  content: "+";
  color: var(--copper-ink);
  font-size: 1rem;
  letter-spacing: 0;
}

.rail[open] > .rail__summary::after { content: "−"; }

.rail__summary:hover,
.rail__summary:focus-visible,
.rail[open] > .rail__summary {
  border-color: var(--copper-ink);
  background: var(--paper);
}

.rail__summary:focus-visible {
  outline: 2px solid var(--copper-ink);
  outline-offset: 3px;
}

.rail__current {
  max-height: 7.5rem;
  overflow: hidden;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: .1em;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity var(--dur-fast, 150ms) linear;
}

.rail.is-over-hero:not([open]) .rail__current { opacity: 0; }

/* The hero's only copy column is on the left. While it owns the viewport the
   compact spine moves to the quiet right edge and its panel opens inward;
   after the hero it returns to the document's left margin. */
@media (min-width: 70.01rem) {
  .rail.is-over-hero {
    right: clamp(.5rem, 1.25vw, 1.15rem);
    left: auto;
  }

  .rail.is-over-hero .rail__panel {
    right: calc(100% + .7rem);
    left: auto;
  }
}

.rail__panel {
  position: absolute;
  left: calc(100% + .7rem);
  top: 50%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 2px minmax(12rem, 1fr);
  gap: .85rem;
  width: min(15rem, calc(100vw - 5rem));
  max-height: min(38rem, calc(100vh - 3rem));
  padding: 1rem;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  background: rgba(250, 248, 244, .98);
  box-shadow: 0 1rem 3rem rgba(31, 29, 25, .12);
  transform: translateY(-50%);
}

.rail__track {
  position: relative;
  display: block;
  width: 2px;
  min-height: 100%;
  background: var(--paper-3);
}

.rail__fill {
  position: absolute;
  inset: 0 0 auto;
  display: block;
  height: var(--rail-pct, 0%);
  background: var(--copper-ink);
  transition: height 120ms linear;
}

.rail__list {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail__chapter {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: .2rem .35rem .2rem .65rem;
  border-left: 2px solid transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: max(.75rem, var(--text-label));
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: .12em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color var(--dur-fast, 150ms) linear,
              border-color var(--dur-fast, 150ms) linear;
}

.rail__chapter:hover,
.rail__chapter:focus-visible {
  border-left-color: var(--paper-3);
  color: var(--copper-ink);
}

.rail__chapter:focus-visible {
  outline: 2px solid var(--copper-ink);
  outline-offset: 2px;
}

.rail__chapter.is-current {
  border-left-color: var(--copper-ink);
  color: var(--copper-ink);
  font-weight: 700;
}

@media (pointer: coarse) {
  .rail__chapter { min-height: 44px; }
}

/* At tablet widths the contents control becomes a slim second header row. Its
   open panel is temporary and bounded; the resting state never steals prose. */
@media (max-width: 70rem) {
  .rail {
    right: auto;
    left: .65rem;
    top: 3.35rem;
    transform: none;
  }

  .rail__summary {
    flex-direction: row;
    width: auto;
    min-width: 44px;
    min-height: 44px;
    padding: .65rem .85rem;
    writing-mode: horizontal-tb;
  }

  .rail__current { max-width: 13rem; }

  .rail__panel {
    position: fixed;
    right: auto;
    left: .65rem;
    top: 6.25rem;
    width: min(20rem, calc(100vw - 1.3rem));
    max-height: calc(100vh - 7rem);
    transform: none;
  }
}

@media (max-width: 32rem) {
  .rail__summary { gap: .65rem; }
  .rail__current { display: none; }
  .rail__panel {
    right: .65rem;
    width: auto;
    grid-template-columns: 2px minmax(0, 1fr);
  }
}

@media (max-height: 30rem) and (min-width: 70.01rem) {
  .rail__summary { min-height: 8rem; }
  .rail__current { display: none; }
  .rail__panel { max-height: calc(100vh - 1rem); }
}

@media (prefers-reduced-motion: reduce) {
  .rail__fill,
  .rail__current { transition: none; }
}

@media print {
  .rail { display: none; }
}
