/* The table of contents rail: the table of contents of an article, on its right, on a white page. A thin rail runs
   beside the entries and steps in for every sub-heading; its lit stretch covers exactly the part of the article on
   screen. The article is plain headings and short paragraphs, only there to be read and scrolled. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #141a1f;           /* text */
  --muted: #5f6872;         /* secondary text, entries out of view */
  --line: #e3e7e9;          /* the borders of the table of contents */
  --rail: #d7dde0;          /* the rail at rest */
  --accent: #0c7f78;        /* the lit stretch, the entry being read */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  scroll-padding-top: 32px;
}

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

body {
  background: var(--page);
  color: var(--ink);
  font-family: 'Schibsted Grotesk Variable', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- the two columns */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 680px) 232px;
  justify-content: center;
  gap: 56px;
  padding: 0 24px;
}

/* ---------------------------------------------------------------- the article */
/* plain headings and short paragraphs: what the table of contents indexes, and lights up as you read */
.doc {
  grid-column: 1;
  grid-row: 1;
  padding: 64px 0 120px;
  min-width: 0;
}

.doc h2,
.doc h3,
.doc h4 {
  scroll-margin-top: 32px;
  outline: none;
}

.doc h2 {
  margin: 56px 0 12px;
  font-size: 24px;
  font-weight: 720;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.doc h2:first-child {
  margin-top: 0;
}

.doc h3 {
  margin: 34px 0 8px;
  font-size: 18.5px;
  font-weight: 680;
  letter-spacing: -0.01em;
}

.doc h4 {
  margin: 26px 0 6px;
  font-size: 16px;
  font-weight: 680;
}

.doc p {
  margin: 0 0 16px;
}

/* ---------------------------------------------------------------- the table of contents */
.toc {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  padding: 64px 0 24px;
  overflow-y: auto;
  scrollbar-width: none;
}

.toc__bar {
  display: none;
}

.toc__title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
}

.toc__nav {
  position: relative;
}

/* the rail: drawn by the script beside the entries, as tall as the list */
.rail {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

.rail__track,
.rail__read,
.rail__ghost,
.rail__halo,
.rail__lit {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail__track {
  stroke: var(--rail);
  stroke-width: 1.5;
}

/* under the entry pointed at, the stretch of rail a press would light */
.rail__ghost {
  stroke: var(--accent);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.rail__ghost.is-on {
  opacity: 0.4;
}

/* the stretch already read, above the lit one */
.rail__read {
  stroke: color-mix(in srgb, var(--accent) 34%, var(--rail));
  stroke-width: 1.5;
}

.rail__halo {
  stroke: var(--accent);
  stroke-width: 7;
  opacity: 0.14;
}

.rail__lit {
  stroke: var(--accent);
  stroke-width: 2;
}

.rail__head {
  fill: var(--page);
  stroke: var(--accent);
  stroke-width: 2;
}

.toc__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* each entry starts after the rail, one step further in for every level */
.toc__list a {
  display: block;
  margin-left: calc(var(--x, 0px) + 10px);
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--muted);
  transition: color 0.25s ease;
}

.toc__list a[data-depth='3'],
.toc__list a[data-depth='4'] {
  font-size: 13px;
}

.toc__list a.is-lit {
  color: var(--ink);
}

.toc__list a[aria-current='true'] {
  color: var(--accent);
  font-weight: 600;
}

@media (hover: hover) and (pointer: fine) {
  .toc__list a:hover {
    color: var(--ink);
  }
}

.toc__list a:focus-visible {
  outline-offset: -1px;
}

.toc__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.toc__left {
  font-variant-numeric: tabular-nums;
}

.toc__up {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s ease, opacity 0.3s ease;
}

.toc__up svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toc__up[hidden] {
  display: inline-flex;
  opacity: 0;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .toc__up:hover {
    color: var(--accent);
  }
}

/* ---------------------------------------------------------------- narrower screens */
@media (max-width: 1240px) {
  .layout {
    grid-template-columns: minmax(0, 680px) 220px;
    gap: 48px;
  }
}

/* on a phone the table of contents is a bar at the top of the screen: it says where you are and opens the list */
@media (max-width: 900px) {
  html {
    scroll-padding-top: 72px;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .doc {
    padding: 28px 16px 96px;
  }

  .doc h2,
  .doc h3,
  .doc h4 {
    scroll-margin-top: 72px;
  }

  .toc {
    position: sticky;
    top: 0;
    z-index: 15;
    max-height: none;
    padding: 0;
    overflow: visible;
  }

  .toc__bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 52px;
    padding: 0 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--page) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-align: left;
    cursor: pointer;
  }

  .toc__ring {
    flex: none;
    width: 22px;
    height: 22px;
    transform: rotate(-90deg);
  }

  .toc__ring circle {
    fill: none;
    stroke: var(--rail);
    stroke-width: 2.4;
  }

  .toc__ring circle + circle {
    stroke: var(--accent);
    stroke-linecap: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
  }

  .toc__bar-words {
    display: grid;
    min-width: 0;
    line-height: 1.25;
  }

  .toc__bar-label {
    font-size: 11.5px;
    color: var(--muted);
  }

  .toc__bar-now {
    overflow: hidden;
    font-size: 14.5px;
    font-weight: 650;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .toc__chevron {
    flex: none;
    width: 16px;
    height: 16px;
    margin-left: auto;
    fill: none;
    stroke: var(--muted);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.4s cubic-bezier(0.34, 1.5, 0.5, 1);
  }

  .toc__bar[aria-expanded='true'] .toc__chevron {
    transform: rotate(180deg);
  }

  .toc__bar:focus-visible {
    outline-offset: -3px;
  }

  .toc__panel {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    max-height: calc(100svh - 80px);
    overflow-y: auto;
    padding: 18px 20px 14px;
    background: var(--page);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 24px 40px -24px rgba(20, 26, 31, 0.28);
    visibility: hidden;
  }

  .toc__title {
    display: none;
  }

  .toc__list a {
    padding-top: 7px;
    padding-bottom: 7px;
    font-size: 15px;
  }

  .toc__list a[data-depth='3'],
  .toc__list a[data-depth='4'] {
    font-size: 14.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toc__list a,
  .toc__chevron,
  .toc__up {
    transition: none;
  }
}
