/* ==========================================================================
   Long-form pages: the legal pages, the insights (all posts and each post)
   and the 404 (tools/pages/build.py, tools/insights/build.py).
   The head: a mono label and the date, the title, a lede. Then the words in a
   reading column beside a sticky contents list (wide screens) or under a
   fold-out one (narrow). doc.js lights the contents list as you read and
   glides to a section when you pick one.
   ========================================================================== */

/* ------------------------------------------------------------------ head */

.doc-head {
  padding: calc(var(--header-h) + clamp(24px, 5vh, 64px)) var(--gutter) 0;
}

.doc-head__top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 24px;
  color: var(--text-mute);
}

.doc-head__label {
  color: var(--ink);
}

.doc-meta__part {
  white-space: nowrap;
}

.doc-head__meta a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* The page's one word, as large as the width allows (sized by its letters). */
.doc-title {
  margin-top: clamp(20px, 4vh, 44px);
  font-size: min(11rem, calc((100vw - 2 * var(--gutter)) / (var(--chars, 8) * 0.95)), 20vh);
  font-stretch: var(--wdth-display);
  font-weight: 500;
  line-height: 0.86;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  font-synthesis: none;
}

.doc-title > span {
  display: inline-block;
}

/* A post's title is a sentence: large, but set as words. */
.doc-title--article {
  max-width: 17ch;
  font-size: clamp(2.375rem, 1.1rem + 4.4vw, 6.25rem);
  font-stretch: 112.5%;
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-transform: none;
  text-wrap: balance;
}

.doc-title--article > span {
  display: block;
}

.doc-lede {
  max-width: 36ch;
  margin-top: clamp(24px, 4.5vh, 48px);
  font-size: clamp(1.25rem, 0.95rem + 1.05vw, 2rem);
  line-height: 1.24;
  letter-spacing: -0.025em;
  text-wrap: pretty;
}

.doc-back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  color: var(--ink);
  background: linear-gradient(currentColor, currentColor) 24px 100% / 0 1px no-repeat;
  transition: background-size 500ms var(--ease-out);
}

.doc-back svg {
  flex: none;
  width: 14px;
  height: 14px;
  transition: translate 420ms var(--ease-out);
}

/* A post's short answer, on white. */
.doc-short {
  display: grid;
  gap: 12px;
  max-width: 64ch;
  margin-top: clamp(28px, 5vh, 56px);
  padding: clamp(20px, 2.4vw, 32px);
  border-radius: clamp(12px, 1.2vw, 18px);
  background: var(--white);
}

.doc-short__label {
  color: var(--text-mute);
  letter-spacing: 0.12em;
}

.doc-short__text {
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.5rem);
  line-height: 1.4;
  letter-spacing: -0.015em;
  text-wrap: pretty;
}

.doc-cover {
  margin: clamp(32px, 6vh, 72px) var(--gutter) 0;
  overflow: hidden;
  aspect-ratio: 5 / 2;
  border-radius: clamp(12px, 1.4vw, 20px);
  background: var(--bone-deep);
}

.doc-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The head plays in: each part rises in turn (no script needed). */
.js .doc-head [data-enter],
.js .doc-cover[data-enter] {
  animation: doc-rise 1000ms var(--ease-out) both;
  animation-delay: calc(80ms + var(--e, 0) * 70ms);
}

@keyframes doc-rise {
  from {
    opacity: 0;
    translate: 0 26px;
  }
}

/* ------------------------------------------------------------------ body */

.doc-body {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
  align-items: start;
  gap: clamp(32px, 5vw, 96px);
  padding: clamp(56px, 10vh, 120px) var(--gutter) 0;
}

.doc-side {
  position: sticky;
  top: calc(var(--header-compact) + 24px);
  display: grid;
  gap: 40px;
  max-height: calc(100svh - var(--header-compact) - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.doc-side::-webkit-scrollbar {
  display: none;
}

.doc-toc__label {
  margin-bottom: 14px;
  color: var(--text-mute);
  letter-spacing: 0.12em;
}

.doc-toc__list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.doc-toc__link {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 10px 0 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9375rem;
  line-height: 1.35;
  color: var(--text-mute);
  transition:
    color 250ms ease,
    padding-left 400ms var(--ease-out);
}

.doc-toc__n {
  flex: none;
  padding-top: 0.2em;
  color: var(--text-faint);
}

/* The section being read: ink, nudged in behind a short rule. */
.doc-toc__link[aria-current="true"] {
  padding-left: 18px;
  color: var(--ink);
}

.doc-toc__link::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 10px;
  height: 1px;
  background: var(--ink);
  scale: 0 1;
  transform-origin: 0 50%;
  transition: scale 400ms var(--ease-out);
}

.doc-toc__link[aria-current="true"]::before {
  scale: 1 1;
}

.doc-policies__list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.doc-policies__link {
  display: block;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9375rem;
  color: var(--text-mute);
  transition: color 250ms ease;
}

.doc-policies__link[aria-current="page"] {
  color: var(--ink);
}

/* Under the words on narrow screens (beside them, wide ones have them already). */
.doc-foot-policies {
  display: none;
  margin: clamp(56px, 9vh, 96px) var(--gutter) 0;
}

/* The fold-out contents list (narrow screens). */
.doc-toc-m {
  display: none;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.doc-toc-m__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  list-style: none;
  cursor: pointer;
  letter-spacing: 0.12em;
}

.doc-toc-m__summary::-webkit-details-marker {
  display: none;
}

.doc-toc-m__icon {
  position: relative;
  width: 12px;
  height: 12px;
}

.doc-toc-m__icon::before,
.doc-toc-m__icon::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 12px;
  height: 1px;
  background: currentColor;
  transition: rotate 400ms var(--ease-out);
}

.doc-toc-m__icon::after {
  rotate: 90deg;
}

.doc-toc-m[open] .doc-toc-m__icon::after {
  rotate: 0deg;
}

.doc-toc-m .doc-toc__list {
  margin-bottom: 4px;
}

/* The fold-out's own rule closes the list (no second line just above it). */
.doc-toc-m .doc-toc__list li:last-child .doc-toc__link {
  border-bottom: 0;
}

/* ------------------------------------------------------------------ the words */

.prose {
  max-width: 70ch;
  font-size: clamp(1.0625rem, 0.99rem + 0.22vw, 1.1875rem);
  line-height: 1.65;
  color: rgb(17 17 17 / 0.8);
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose p {
  text-wrap: pretty;
}

.prose a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.prose strong {
  font-weight: 600;
  color: var(--ink);
}

.prose code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--bone-deep);
}

.prose__h2,
.prose__h3 {
  color: var(--ink);
  scroll-margin-top: calc(var(--header-compact) + 32px);
  text-wrap: balance;
}

.prose__h2 {
  margin-top: 2.4em;
  font-size: clamp(1.5rem, 1.05rem + 1.45vw, 2.5rem);
  font-stretch: 112.5%;
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.prose > .prose__h2:first-child {
  margin-top: 0;
}

.prose__h2 > span {
  display: block;
}

.prose__n {
  margin-bottom: 14px;
  color: var(--text-mute);
  letter-spacing: 0.12em;
}

.prose__h3 {
  margin-top: 2em;
  font-size: clamp(1.1875rem, 1.05rem + 0.5vw, 1.5rem);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.prose > .prose__h2 + *,
.prose > .prose__h3 + * {
  margin-top: 0.8em;
}

.prose__list {
  display: grid;
  gap: 0.55em;
  padding: 0;
  list-style: none;
}

.prose__list > li {
  position: relative;
  padding-left: 1.6em;
}

.prose__list > li::before {
  content: "";
  position: absolute;
  left: 0.15em;
  top: 0.82em;
  width: 0.6em;
  height: 1px;
  background: currentColor;
}

.prose__list--num {
  counter-reset: n;
}

.prose__list--num > li {
  counter-increment: n;
  padding-left: 2.2em;
}

.prose__list--num > li::before {
  content: counter(n, decimal-leading-zero);
  top: 0.42em;
  width: auto;
  height: auto;
  font-family: var(--font-mono);
  font-size: 0.72em;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  background: none;
}

.prose__quote {
  margin: 2em 0;
  padding: 0 0 0 clamp(20px, 2.4vw, 36px);
  border-left: 2px solid var(--ink);
  font-size: clamp(1.375rem, 1.05rem + 1.1vw, 2rem);
  line-height: 1.24;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-wrap: balance;
}

.prose__stat {
  display: grid;
  gap: 12px;
  margin: 2em 0;
  padding: clamp(20px, 2.6vw, 36px) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.prose__stat-num {
  font-size: clamp(3.25rem, 1.9rem + 4.4vw, 6.5rem);
  font-stretch: var(--wdth-display);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.prose__stat-label {
  color: var(--text-mute);
  letter-spacing: 0.12em;
}

.prose__callout {
  margin: 2em 0;
  padding: clamp(18px, 2.2vw, 30px);
  border-radius: 14px;
  color: var(--ink);
  background: var(--white);
}

.prose__callout p + p {
  margin-top: 0.8em;
}

.prose__callout-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-mute);
  letter-spacing: 0.12em;
}

.prose__callout-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* "Watch out": the one that needs to be seen, on ink. */
.prose__callout--warning {
  color: var(--bone);
  background: var(--ink);
}

.prose__callout--warning .prose__callout-label {
  color: var(--on-ink-mute);
}

.prose__terms {
  margin: 1.6em 0;
  border-top: 1px solid var(--line);
}

.prose__term {
  display: grid;
  grid-template-columns: minmax(0, 13em) minmax(0, 1fr);
  gap: 6px 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.prose__term dt {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.prose__term dd {
  margin: 0;
}

.prose__contact {
  margin-top: 3em !important;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--text-mute);
}

/* ------------------------------------------------------------------ questions */

.doc-faq {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
  align-items: start;
  gap: 24px clamp(32px, 5vw, 96px);
  padding: clamp(88px, 14vh, 160px) var(--gutter) 0;
}

.doc-faq__head {
  display: grid;
  gap: 12px;
}

.doc-faq__label {
  color: var(--text-mute);
}

.doc-faq__title {
  font-size: clamp(1.75rem, 1.2rem + 1.6vw, 3rem);
  font-stretch: 112.5%;
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.03em;
}

.doc-faq__list {
  max-width: 70ch;
  border-top: 1px solid var(--line);
}

.doc-faq__item {
  border-bottom: 1px solid var(--line);
}

.doc-faq__q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 64px;
  padding: 18px 0;
  list-style: none;
  cursor: pointer;
  font-size: clamp(1.0625rem, 0.95rem + 0.55vw, 1.4375rem);
  line-height: 1.3;
  letter-spacing: -0.015em;
}

.doc-faq__q::-webkit-details-marker {
  display: none;
}

.doc-faq__icon {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
}

.doc-faq__icon::before,
.doc-faq__icon::after {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 14px;
  height: 1.5px;
  background: currentColor;
  transition: rotate 400ms var(--ease-out);
}

.doc-faq__icon::after {
  rotate: 90deg;
}

.doc-faq__item[open] .doc-faq__icon::after {
  rotate: 0deg;
}

.doc-faq__a {
  padding: 0 0 22px;
  max-width: 62ch;
  font-size: clamp(1rem, 0.96rem + 0.18vw, 1.125rem);
  line-height: 1.6;
  color: rgb(17 17 17 / 0.76);
}

.doc-faq__a a {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ start a project */

.doc-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 24px 48px;
  margin: clamp(88px, 14vh, 160px) var(--gutter) 0;
  padding: clamp(28px, 4vw, 64px);
  border-radius: clamp(16px, 1.6vw, 24px);
  color: var(--bone);
  background: var(--ink);
}

.doc-cta__text {
  max-width: 30ch;
  font-size: clamp(1.375rem, 1rem + 1.5vw, 2.625rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

/* The header's pill, turned bone on the ink. */
.doc-cta .btn-cta {
  color: var(--ink);
  background: var(--bone);
}

/* The home page's rows, on plain paper here (the grain would start in a band under the head). */
.insights--page,
.doc-more {
  background: none;
}

.insights--page::before,
.doc-more::before {
  display: none;
}

/* The other posts, under a post: the home page's rows. */
.doc-more {
  margin-top: clamp(24px, 4vh, 48px);
}

.doc-more .insights__top {
  grid-template-columns: minmax(0, 1fr) auto;
}

.insights--page {
  padding-top: clamp(40px, 7vh, 88px);
}

.ins__meta {
  color: var(--text-mute);
  letter-spacing: 0.08em;
}

/* ------------------------------------------------------------------ 404 */

.nf {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100svh;
  padding: clamp(18px, 2.2vw, 28px) var(--gutter) clamp(32px, 6vh, 64px);
}

.nf__logo {
  justify-self: start;
}

.nf__logo img {
  width: clamp(120px, 8vw, 146px);
  height: auto;
}

.nf__body {
  display: grid;
  align-content: center;
  gap: clamp(18px, 3vh, 28px);
  padding-top: clamp(40px, 8vh, 96px);
}

.nf__label {
  color: var(--text-mute);
}

.nf__title {
  max-width: 9ch;
  font-size: clamp(3.25rem, 0.6rem + 10vw, 10.5rem);
  font-stretch: var(--wdth-display);
  font-weight: 500;
  line-height: 0.86;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  font-synthesis: none;
}

.nf__text {
  max-width: 34ch;
  font-size: clamp(1.125rem, 1rem + 0.6vw, 1.5rem);
  line-height: 1.35;
  letter-spacing: -0.015em;
  text-wrap: pretty;
}

.nf__links {
  display: grid;
  max-width: 760px;
  margin-top: clamp(8px, 2vh, 20px);
  border-top: 1px solid var(--line);
}

.nf__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(14px, 2vh, 20px) 0;
  border-bottom: 1px solid var(--line);
  font-size: clamp(1.25rem, 1rem + 1vw, 2rem);
  letter-spacing: -0.02em;
  transition: padding-left 450ms var(--ease-out);
}

.nf__link svg {
  flex: none;
  width: 18px;
  height: 18px;
  transition: translate 420ms var(--ease-out);
}

.nf__mail {
  color: var(--text-mute);
}

.nf__mail a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* ------------------------------------------------------------------ hover */

@media (hover: hover) and (pointer: fine) {
  .doc-back:hover {
    background-size: calc(100% - 24px) 1px;
  }

  .doc-back:hover svg {
    translate: -3px 0;
  }

  .doc-toc__link:hover,
  .doc-policies__link:hover {
    color: var(--ink);
  }

  .prose a:hover,
  .nf__mail a:hover {
    text-decoration-thickness: 2px;
  }

  .doc-cta .btn-cta:hover {
    background: var(--white);
  }

  .nf__link:hover {
    padding-left: 12px;
  }

  .nf__link:hover svg {
    translate: 4px 0;
  }
}

/* ------------------------------------------------------------------ narrow */

@media (max-width: 959px) {
  .doc-body,
  .doc-faq {
    grid-template-columns: minmax(0, 1fr);
  }

  .doc-body {
    gap: 36px;
    padding-top: clamp(40px, 7vh, 72px);
  }

  .doc-side {
    display: none;
  }

  .doc-toc-m,
  .doc-foot-policies {
    display: block;
  }
}

@media (max-width: 719px) {
  .doc-cover {
    aspect-ratio: 16 / 9;
  }

  .doc-cta {
    align-items: flex-start;
    flex-direction: column;
  }

  .prose__term {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .js .doc-head [data-enter],
  .js .doc-cover[data-enter] {
    animation: none;
  }

  .doc-toc__link,
  .doc-toc__link::before,
  .nf__link,
  .nf__link svg {
    transition: none;
  }
}

/* Room above the footer: the legal pages and the insights index ended flush on it
   (the article ends with the other posts, which bring their own). */
.doc--legal,
.doc--index {
  padding-bottom: clamp(88px, 14vh, 160px);
}

/* Phones: the site's section rhythm (--sec-top / --sec-bot / --sec-end, tokens.css),
   so every gap between two sections reads the same. */
@media (max-width: 719px) {
  .doc--legal,
  .doc--index {
    padding-bottom: var(--sec-end);
  }

  .doc-cta {
    margin-top: var(--sec-top);
  }
}
