/* Contents on a taut thread: the contents page of a book, Low Water, on warm paper. Each chapter's title on the left
   in Newsreader (a variable serif, weight 200 to 800), its page on the right, and a hairline between them instead of
   dots. The script draws the lines, moves the pages and changes the weight. */
:root {
  --paper: #f4f1ea;         /* the page */
  --ink: #141414;           /* the titles and the taut line */
  --grey: #8f8a80;          /* the pages at rest and the small texts */
  --line: rgba(20, 20, 20, 0.24); /* the line at rest, hanging */
  --accent: #e2432a;        /* the page under the pointer, while it counts */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Newsreader Variable', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  --pad: clamp(16px, 6vw, 96px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100svh;
  padding: clamp(18px, 3.4vw, 40px) var(--pad) clamp(18px, 3vw, 36px);
}

/* ---------------------------------------------------------------- the top line and the hint */
.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 15px;
  overflow: hidden;
}

.top__name,
.top__note {
  display: inline-block;
}

.top__name {
  font-weight: 560;
  letter-spacing: 0.005em;
}

.top__note {
  color: var(--grey);
  font-style: normal;
  font-weight: 400;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--grey);
  text-align: center;
}

/* ---------------------------------------------------------------- the contents */
.toc {
  align-self: center;
  justify-self: center;
  width: min(100%, 760px);
  touch-action: none;
}

.entry {
  position: relative;
  display: grid;
  align-items: baseline;
  padding: 9px 0;
  color: inherit;
  text-decoration: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.entry__title,
.entry__num {
  grid-area: 1 / 1;
  justify-self: start;
}

/* the mask lets the title rise into place when the page opens */
.entry__title {
  display: block;
  overflow: hidden;
  padding: 0 0.12em 0.08em 0;
  margin-bottom: -0.08em;
  font-size: clamp(21px, 2.45vw, 31px);
  line-height: 1.2;
}

.entry__text {
  display: inline-block;
  white-space: nowrap;
  font-variation-settings: 'wght' 320;
  letter-spacing: -0.005em;
}

.entry__num {
  display: block;
  font-size: clamp(15px, 1.4vw, 18px);
  font-weight: 430;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--grey);
  white-space: nowrap;
  will-change: transform;
  transition: color 0.35s ease;
}

.entry__digits {
  display: inline-block;
}

.entry.is-on .entry__num {
  color: var(--ink);
}

/* the count has landed on the page: it lights up */
.entry.is-on.is-set .entry__num {
  color: var(--accent);
}

.entry__lead {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.entry__lead path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  transition: stroke 0.35s ease;
}

.entry.is-on .entry__lead path {
  stroke: var(--ink);
}

.entry:focus-visible .entry__text {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

@media (max-width: 640px) {
  .top {
    font-size: 14px;
  }

  .entry {
    padding: 8px 0;
  }

  .entry__title {
    font-size: 20px;
  }

  .entry__num {
    font-size: 14px;
  }
}
