/* Page contents: one quiet bar that pins to the top of the viewport and fades into the page.
   The caption, current section, count and back-to-top share a single outline; on small screens the
   caption is visually hidden (kept for assistive tech) and the title stays on one line. */
.reading-sections{--bar-h:52px;--back-w:48px;position:sticky;top:8px;z-index:20;isolation:isolate;
 display:grid;grid-template-columns:minmax(0,1fr) 0;align-items:stretch;width:100%;max-width:100%;margin:24px 0 32px;
 border:1px solid var(--rule);border-radius:12px;background:var(--paper);box-shadow:0 4px 16px #0000000c;
 transition:grid-template-columns 130ms cubic-bezier(.2,.7,.3,1),border-color 90ms,box-shadow 90ms}
.reading-sections.has-back-top{grid-template-columns:minmax(0,1fr) var(--back-w)}
.reading-sections:has(.reading-sections-menu[open]){border-color:var(--accent)}
/* While pinned, content scrolling underneath fades out behind the bar instead of showing around it. */
.reading-sections.is-pinned::before{content:"";position:absolute;inset:-10px -12px -14px;z-index:-1;pointer-events:none;
 background:linear-gradient(to bottom,var(--paper) 0,var(--paper) calc(100% - 14px),transparent 100%)}
/* With the list open, nothing may show through the gap between the bar and the panel. */
.reading-sections.is-pinned:has(.reading-sections-menu[open])::before{inset-block-end:-7px;background:var(--paper)}

.reading-sections-menu{position:static;min-width:0}
.reading-sections-menu>summary{position:relative;display:grid;grid-template-columns:max-content minmax(0,1fr) max-content 8px;align-items:center;gap:12px;
 box-sizing:border-box;height:var(--bar-h);padding:0 16px;list-style:none;cursor:pointer;color:var(--ink);border-radius:11px;transition:background-color 90ms}
.reading-sections.has-back-top .reading-sections-menu>summary{border-start-end-radius:0;border-end-end-radius:0}
.reading-sections-menu[open]>summary{background:color-mix(in srgb,var(--accent) 7%,var(--paper))}
.reading-sections-menu>summary::-webkit-details-marker{display:none}
.reading-sections-caption{font-size:12px;font-weight:500;color:var(--muted);white-space:nowrap}
.reading-sections-current{display:block;min-width:0;font-size:14px;font-weight:600;line-height:1.4;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.reading-sections-count{min-width:4.5ch;font-size:11px;font-variant-numeric:tabular-nums;text-align:end;white-space:nowrap;color:var(--muted);direction:ltr;unicode-bidi:isolate}
.reading-sections-menu>summary .menu-chevron{width:7px;height:7px;border-right:1.5px solid currentColor;border-bottom:1.5px solid currentColor;transform:rotate(45deg);margin-top:-4px;transition:transform 110ms}
.reading-sections-menu[open]>summary .menu-chevron{transform:rotate(225deg);margin-top:4px}

/* The full list opens as a panel anchored to the whole bar. */
.reading-sections-menu:not([open])>.reading-sections-links{display:none}
.reading-sections .reading-sections-links{position:absolute;inset-inline:-1px;top:calc(100% + 6px);display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:4px;margin:0;padding:12px;
 border:1px solid var(--rule);border-radius:12px;background:var(--paper);box-shadow:0 10px 32px #00000020;max-height:60dvh;overflow:auto;overscroll-behavior:contain}
.reading-sections .reading-sections-links>a{display:flex;align-items:center;min-height:44px;margin:0;padding:10px 12px;font-size:14px;line-height:1.4;font-weight:500;border:0;border-radius:8px;color:var(--ink);text-decoration:none;overflow-wrap:anywhere}
.reading-sections .reading-sections-links>a[aria-current]{background:var(--panel);font-weight:650}
.reading-section-target{scroll-margin-top:0}

/* Back to top is a cell of the same bar, separated by an inset divider, and slides in once the reader scrolls. */
.reading-back-top{display:grid;place-items:center;box-sizing:border-box;width:100%;min-width:0;padding:0;border:0;border-radius:0 11px 11px 0;background:transparent;color:var(--muted);cursor:pointer;overflow:hidden;contain:inline-size;
 opacity:0;visibility:hidden;pointer-events:none;transform:translateX(5px);transition:opacity 90ms,transform 130ms,visibility 130ms,background-color 90ms,color 90ms}
.reading-back-top svg{display:block;margin:auto}
.has-back-top>.reading-back-top{opacity:1;visibility:visible;pointer-events:auto;transform:none;box-shadow:inset 1px 0 var(--rule)}
[dir=rtl] .reading-back-top{border-radius:11px 0 0 11px;transform:translateX(-5px)}
[dir=rtl] .has-back-top>.reading-back-top{transform:none;box-shadow:inset -1px 0 var(--rule)}

@media(hover:hover) and (pointer:fine){
 .reading-sections-menu>summary:hover,.reading-back-top:hover,.reading-sections .reading-sections-links>a:hover{background:var(--panel)}
 .reading-back-top:hover{color:var(--ink)}
}
.reading-sections :is(summary,a,button):focus-visible{outline:2px solid var(--accent);outline-offset:-3px}

/* Below 720px there is no room for a caption beside the title: it stays for screen readers only. */
@media(max-width:720px){
 .reading-sections-caption{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
 .reading-sections-menu>summary{grid-template-columns:minmax(0,1fr) max-content 8px;gap:8px;padding:0 12px}
}
@media(max-width:600px){
 .reading-sections{--bar-h:48px;--back-w:44px;top:6px;margin:20px 0 24px}
 .reading-sections-current{font-size:13px;line-height:1.35}
 .reading-sections-count{font-size:10px}
 .reading-sections .reading-sections-links{grid-template-columns:repeat(2,minmax(0,1fr));padding:8px}
 .reading-sections .reading-sections-links>a{padding:10px 8px;font-size:13px}
 .reading-section-target{scroll-margin-top:0}
}
@media(max-width:340px){.reading-sections .reading-sections-links{grid-template-columns:minmax(0,1fr)}}
@media(prefers-reduced-motion:reduce){.reading-sections,.reading-back-top,.has-back-top>.reading-back-top,.reading-sections-menu>summary,.reading-sections-menu>summary .menu-chevron{transition:none;transform:none}}
@media print{.reading-sections{display:none}}
