/* Focus reader — styles for the mobile progressive-disclosure layer.
 *
 * Everything here is scoped to html.has-focus-reader, which reader.js only sets
 * on narrow viewports. Desktop keeps the original article layout untouched.
 * Colours come from each host's own custom properties where they exist, with
 * neutral fallbacks, so one stylesheet serves six different palettes.
 *
 * Regenerated from _tools/reader/ by _tools/install_reader.py — edit there.
 */

.chapter-rail {
  display: none;
}

.chapter__toggle {
  all: unset;
  cursor: pointer;
  display: block;
  font: inherit;
  color: inherit;
  width: 100%;
}

.chapter__chevron,
.chapter__hint {
  display: none;
}

@media (max-width: 860px) {
  html.has-focus-reader .chapter-rail {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 calc(50% - 50vw) 22px;
    padding: 10px max(16px, calc(50vw - 50%));
    background: var(--reader-rail-bg, var(--paper, var(--white, #fff)));
    border-bottom: 1px solid var(--line, var(--rule, rgba(0, 0, 0, 0.12)));
    backdrop-filter: saturate(1.4) blur(6px);
  }

  html.has-focus-reader .chapter-rail__track {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    flex: 1 1 auto;
    -webkit-overflow-scrolling: touch;
  }

  html.has-focus-reader .chapter-rail__track::-webkit-scrollbar {
    display: none;
  }

  html.has-focus-reader .chapter-rail__chip {
    flex: 0 0 auto;
    scroll-snap-align: start;
    max-width: 62vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--line, var(--rule, rgba(0, 0, 0, 0.16)));
    border-radius: 999px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 0.78rem;
    line-height: 1;
    padding: 8px 13px;
    cursor: pointer;
  }

  html.has-focus-reader .chapter-rail__chip.is-current {
    border-color: currentColor;
    background: var(--reader-chip-active, rgba(127, 127, 127, 0.14));
    font-weight: 600;
  }

  html.has-focus-reader .chapter-rail__chip b {
    font-variant-numeric: tabular-nums;
    opacity: 0.55;
    margin-right: 7px;
  }

  html.has-focus-reader .chapter-rail__all {
    flex: 0 0 auto;
    border: 0;
    background: var(--reader-accent, var(--ink, var(--midnight, #1b2432)));
    color: var(--reader-accent-ink, #fff);
    border-radius: 999px;
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 9px 12px;
    cursor: pointer;
  }

  /* The host's own contents list, superseded by the rail on small screens.
   * Hidden with display:none only under the reader class, so a browser without
   * JS keeps the original navigation. */
  html.has-focus-reader .is-reader-replaced {
    display: none;
  }

  /* --- the chapters themselves ------------------------------------------- */

  html.has-focus-reader .chapter {
    border-top: 1px solid var(--line, var(--rule, rgba(0, 0, 0, 0.12)));
    padding-top: 4px;
  }

  html.has-focus-reader .chapter__heading {
    margin: 0;
  }

  html.has-focus-reader .chapter__toggle {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 18px 0 6px;
    min-height: 44px; /* comfortable tap target */
  }

  html.has-focus-reader .chapter__label {
    flex: 1 1 auto;
  }

  html.has-focus-reader .chapter__chevron {
    display: block;
    flex: 0 0 auto;
    width: 11px;
    height: 11px;
    margin-top: 0.45em;
    border-right: 2.2px solid currentColor;
    border-bottom: 2.2px solid currentColor;
    transform: rotate(45deg);
    opacity: 0.5;
    transition: transform 0.18s ease;
  }

  html.has-focus-reader .chapter.is-open .chapter__chevron {
    transform: rotate(-135deg);
    opacity: 0.85;
  }

  html.has-focus-reader .chapter__hint {
    display: block;
    margin: 0 0 18px;
    font-size: 0.92rem;
    line-height: 1.5;
    opacity: 0.66;
    cursor: pointer;
  }

  html.has-focus-reader .chapter.is-open .chapter__hint {
    display: none;
  }

  html.has-focus-reader .chapter__body {
    padding-bottom: 10px;
    animation: chapter-in 0.2s ease both;
  }

  html.has-focus-reader .chapter__body[hidden] {
    display: none;
  }
}

@keyframes chapter-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chapter__body,
  .chapter__chevron {
    animation: none !important;
    transition: none !important;
  }
}
