/* Licensed to account 52c7da1aea3f, 2026-10-19. Moving parts. */
/* Scroll chapters, the mechanics: the counter wheels, the mark on the title being read, the list held beside the text, the strip on a narrow window.
   Moving parts. What the table of contents does in each state, on attributes the engine writes; the look of the preview follows.
   Readable source: components/scroll-chapters/scroll-chapters.css */

/* ---------- colours and sizes of the states ---------- */

/* Three colours, one tone and five sizes, zero specificity.
   Set any of them on the block marked data-scroll-chapters, or on anything
   above it. --scroll-chapters-quiet is the strength of the ink of what is
   not being read, as a percentage. */
:where([data-scroll-chapters]) {
  --scroll-chapters-css: 1;
  --scroll-chapters-accent: #ff4a00;
  --scroll-chapters-quiet: 42%;
  --scroll-chapters-pin: 5px;
  --scroll-chapters-shift: clamp(11px, 1vw, 15px);
  --scroll-chapters-top: clamp(24px, 9vh, 96px);
  --scroll-chapters-strip: #15100c;
  --scroll-chapters-strip-ink: #f4ece0;
  --scroll-chapters-bar: clamp(52px, 7.4vh, 60px);
  --scroll-chapters-gutter: clamp(20px, 5.4vw, 40px);
  --scroll-chapters-ease: cubic-bezier(0.22, 0.7, 0.12, 1);
}

/* ---------- the counter ---------- */

/* A window one figure tall, on the baseline of the text around it; each
   wheel is a column of figures behind it, over a figure that is not shown
   and gives the wheel its width. */
.scroll-chapters-drum {
  display: inline-block;
  margin: 0 -0.07em;
  padding: 0 0.07em;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 9%, #000 91%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 9%, #000 91%, transparent);
}

.scroll-chapters-wheel {
  position: relative;
  display: inline-block;
}

.scroll-chapters-wheel::before {
  content: "0";
  visibility: hidden;
}

.scroll-chapters-figures {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  white-space: pre;
  line-height: 1;
  text-align: center;
  will-change: transform;
}

/* The value as text, for a screen reader, out of sight. */
.scroll-chapters-say {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.scroll-chapters-probe {
  position: absolute;
  display: block;
  width: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- a line of the list ---------- */

/* The number of the line being read comes out of the quiet. */
[data-scroll-chapters-ready] [data-scroll-chapters-item-number] {
  opacity: var(--scroll-chapters-quiet);
  transition: opacity 0.6s;
}

[data-scroll-chapters-ready] [data-scroll-chapters-state="current"] [data-scroll-chapters-item-number] {
  opacity: 1;
}

[data-scroll-chapters-item]:focus-visible,
[data-scroll-chapters-item] a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

[data-scroll-chapters] :focus-visible[tabindex="-1"] {
  outline: 2px solid currentColor;
  outline-offset: 6px;
}

/* The ink of a title: quiet, and at full strength from its first letter to
   as far as the chapter has been read. A title on several lines takes its
   ink line after line. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  [data-scroll-chapters-ready] .scroll-chapters-ink {
    background-image: linear-gradient(to right, color-mix(in srgb, currentColor var(--scroll-chapters-lit, var(--scroll-chapters-quiet)), transparent) calc(var(--scroll-chapters-to, 0%) - 6%), color-mix(in srgb, currentColor var(--scroll-chapters-quiet), transparent) var(--scroll-chapters-to, 0%));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

/* Under the pointer a title has all its ink. */
@media (hover: hover) {
  [data-scroll-chapters-ready] [data-scroll-chapters-item]:hover .scroll-chapters-ink {
    background-image: none;
    -webkit-text-fill-color: currentColor;
  }
}

/* The pin: one small square of the accent hung in the margin of the list,
   beside the line being read. It goes from a line to another in one move. */
[data-scroll-chapters-ready] [data-scroll-chapters-list] {
  position: relative;
  margin-left: calc(var(--scroll-chapters-shift) * -1);
  padding-left: var(--scroll-chapters-shift);
}

.scroll-chapters-pin {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--scroll-chapters-pin);
  height: var(--scroll-chapters-pin);
  margin-top: calc(var(--scroll-chapters-pin) / -2);
  background-color: var(--scroll-chapters-accent);
  pointer-events: none;
}

/* ---------- beside the text, on a wide window ---------- */

/* Held in the window while its block scrolls by. */
[data-scroll-chapters-mode="side"] [data-scroll-chapters-nav] {
  position: sticky;
  top: var(--scroll-chapters-top);
  align-self: flex-start;
  box-sizing: border-box;
  max-height: calc(100vh - var(--scroll-chapters-top) * 2);
}

/* A list taller than the window scrolls on its own, with no bar. */
[data-scroll-chapters-mode="side"] [data-scroll-chapters-list] {
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

/* Its lines fade out at the two ends while it does. */
[data-scroll-chapters-mode="side"] [data-scroll-chapters-list][data-scroll-chapters-tall] {
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 22px, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 22px, #000 calc(100% - 22px), transparent);
}

[data-scroll-chapters-list]::-webkit-scrollbar {
  display: none;
}

/* ---------- a strip at the foot of a narrow window ---------- */

/* The whole table becomes a sheet under the edge of the window: only its
   bar shows, and the sheet rises when the bar is pressed. It is away while
   the block is not being read. */
[data-scroll-chapters-mode="strip"] [data-scroll-chapters-nav] {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  box-sizing: border-box;
  width: auto;
  max-width: none;
  max-height: 86vh;
  max-height: 86svh;
  margin: 0;
  padding: 0 var(--scroll-chapters-gutter) calc(var(--scroll-chapters-gutter) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background-color: var(--scroll-chapters-strip);
  color: var(--scroll-chapters-strip-ink);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.9s var(--scroll-chapters-ease), visibility 0s 0.9s;
}

[data-scroll-chapters-mode="strip"] [data-scroll-chapters-nav][data-scroll-chapters-in] {
  transform: translateY(calc(100% - var(--scroll-chapters-bar) - env(safe-area-inset-bottom, 0px)));
  visibility: visible;
  transition: transform 0.9s var(--scroll-chapters-ease), visibility 0s;
}

[data-scroll-chapters-mode="strip"] [data-scroll-chapters-nav][data-scroll-chapters-in][data-scroll-chapters-open] {
  transform: none;
}

/* The page keeps the height of the bar free under its last line. */
[data-scroll-chapters][data-scroll-chapters-mode="strip"]::after {
  content: "";
  display: block;
  flex: none;
  width: 100%;
  height: var(--scroll-chapters-bar);
}

/* The bar: the number, the title being read, how many there are. */
.scroll-chapters-bar {
  display: none;
}

[data-scroll-chapters-mode="strip"] .scroll-chapters-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: block;
  margin: 0 calc(var(--scroll-chapters-gutter) * -1) clamp(4px, 1.4vh, 14px);
  background-color: var(--scroll-chapters-strip);
}

.scroll-chapters-toggle {
  appearance: none;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 14px;
  width: 100%;
  height: var(--scroll-chapters-bar);
  margin: 0;
  padding: 0 var(--scroll-chapters-gutter);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 14px;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.scroll-chapters-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: -5px;
}

.scroll-chapters-bar-number,
.scroll-chapters-bar-total,
.scroll-chapters-now {
  transition: opacity 0.45s;
}

/* The number of the strip is in the accent. */
.scroll-chapters-bar-number {
  color: var(--scroll-chapters-accent);
}

/* The title being read, and the one it rolls to, on the same wheel as the
   number. */
.scroll-chapters-now {
  display: block;
  height: 1.3em;
  overflow: hidden;
}

.scroll-chapters-now-strip {
  display: block;
  transform: translateY(calc(var(--scroll-chapters-turn, 0) * -1.3em));
}

.scroll-chapters-now-row {
  display: block;
  height: 1.3em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scroll-chapters-bar-total {
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, currentColor 50%, transparent);
}

.scroll-chapters-bar-total::before {
  content: "/ ";
}

/* A plus that turns into a cross while the sheet is up. */
.scroll-chapters-caret {
  position: relative;
  display: block;
  width: 11px;
  height: 11px;
  transition: transform 0.7s var(--scroll-chapters-ease);
}

.scroll-chapters-caret::before,
.scroll-chapters-caret::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1.5px;
  margin-top: -0.75px;
  background-color: currentColor;
}

.scroll-chapters-caret::after {
  transform: rotate(90deg);
}

[data-scroll-chapters-open] .scroll-chapters-caret {
  transform: rotate(135deg);
}

[data-scroll-chapters-open] .scroll-chapters-bar-number,
[data-scroll-chapters-open] .scroll-chapters-bar-total,
[data-scroll-chapters-open] .scroll-chapters-now {
  opacity: 0;
}

/* ---------- forced colours and reduced motion ---------- */

@media (forced-colors: active) {
  [data-scroll-chapters-ready] .scroll-chapters-ink {
    background-image: none;
    -webkit-text-fill-color: currentColor;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-scroll-chapters-ready] [data-scroll-chapters-item-number],
  [data-scroll-chapters-mode="strip"] [data-scroll-chapters-nav],
  .scroll-chapters-caret,
  .scroll-chapters-bar-number,
  .scroll-chapters-bar-total,
  .scroll-chapters-now {
    transition-duration: 0.01s !important;
    transition-delay: 0s !important;
  }
}

/* ---------- look, left out of the Webflow Embed ---------- */

/* Clinix Studio: the look of the preview (the scroll-chapters-* classes of
   the essay page, set in Instrument Sans and Geist Mono on #f4ece0) is left
   out of this copy on purpose. The blog article keeps its own type and
   layout in src/pages/blog/[slug].astro, and sets the accent, the strip
   colours and the sizes through the custom properties above, on the block.
   The mechanics above are the file as shipped. */
