/* The letter page type (Join and Why). Its elements:
     the content    one centred column of text
     the contents   its parts (each h2 with an id) in the left margin, the one being read filled
                    (src/letter/contents.js); the right margin stays empty. Where the screen is too
                    narrow for margins, there are no contents
     .wide/.full    anything set between paragraphs, wider than the column or edge to edge
     .tldr          the short version, shown instead of the rest by the TL;DR setting
     the settings   Adjust, the one word in the top-right corner (src/letter/settings.js)
     in the text    h2 a part, h3 one below it; lists; and in red, anything to press: a link, an
                    address that copies itself (src/letter/blocks.js)
   The page scrolls; the text dissolves before it reaches the words fixed in the corners: below
   the top-right word (the head) and above the page names' row (the foot). */
/* Registered: the base size resolves to pixels (scripts read it), and the Size setting's scale
   can glide the text to its new size instead of snapping. */
@property --letter-size {
  syntax: '<length>';
  inherits: true;
  initial-value: 18px;
}
@property --letter-scale {
  syntax: '<number>';
  inherits: true;
  initial-value: 1;
}
/* The column and margins are measured from the base size (34 and 15 of it), so changing the
   text's size reflows the words but never moves the column, the margins or what is in them. */
.letter,
.letter-contents {
  --letter-size: clamp(18px, calc(12.5px + 0.55vw), 21px);
  --letter-measure: calc(34 * var(--letter-size));
  --letter-margin: calc(15 * var(--letter-size));
  --letter-top: clamp(84px, 13vh, 150px);
}
.letter {
  --letter-type: calc(var(--letter-size) * var(--letter-scale));
  --letter-leading: 1.6;
  --letter-gutter: max(24px, calc(var(--border) * 1.5));
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--letter-gutter), 1fr)
    [wide-start] minmax(0, var(--letter-margin))
    [column-start] min(var(--letter-measure), 100% - 2 * var(--letter-gutter))
    [column-end] minmax(0, var(--letter-margin))
    [wide-end] minmax(var(--letter-gutter), 1fr)
    [full-end];
  align-content: start;
  padding: var(--letter-top) 0 clamp(120px, 24vh, 260px);
  font-family: var(--letter-font, inherit);
  font-size: var(--letter-type);
  font-weight: var(--text-weight, 300);
  line-height: var(--letter-leading);
  letter-spacing: -0.004em;
  text-wrap: pretty;
  hanging-punctuation: first;
  transition: --letter-scale 480ms var(--flow);
}
.letter > * {
  grid-column: column;
  margin: 0;
}
.letter > .wide {
  grid-column: wide;
}
.letter > .full {
  grid-column: full;
}
.letter > .tldr,
.letter.is-tldr > :not(.tldr) {
  display: none;
}
.letter.is-tldr > .tldr {
  display: block;
}
/* One rhythm: a paragraph's worth of air between paragraphs, more before a part, less after its
   name, so each name sits with what it names. */
.letter > * + *,
.letter > .tldr > * + * {
  margin-top: 0.85em;
}
.letter > .tldr + * {
  margin-top: 0; /* the short version, hidden, takes no air */
}
.letter h2,
.letter h3 {
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.25;
  text-wrap: balance;
  scroll-margin-top: calc(var(--letter-top) - 0.2em);
}
.letter h2 {
  font-size: 1.3em;
}
.letter h3 {
  font-size: 1em;
  font-weight: 500;
}
.letter > * + h2 {
  margin-top: 2.2em;
}
.letter > * + h3 {
  margin-top: 1.5em;
}
.letter > h2 + *,
.letter > h3 + * {
  margin-top: 0.45em;
}
.letter ul {
  padding-left: 1.1em;
}
.letter li + li {
  margin-top: 0.4em;
}
.letter strong {
  font-weight: 500;
}
/* Anything to press, in the text: red, and nothing else about it changes until it is pointed at. */
.letter a,
.letter .letter-copy {
  color: var(--layer-accent);
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color 140ms linear;
}
.letter a:hover,
.letter .letter-copy:hover {
  text-decoration-color: currentColor;
}
.letter .letter-copy {
  padding: 0;
  border: 0;
  background: none;
  font: 0.84em/1 ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  cursor: copy;
}
.letter a:focus-visible,
.letter .letter-copy:focus-visible,
.letter-contents a:focus-visible {
  outline: 1px solid var(--rose);
  outline-offset: 2px;
  border-radius: 0.2em;
}
/* The contents: held level with the top of the text, set toward it, the width of the margin;
   above the head's fade, so they never dissolve. */
.letter-contents {
  position: fixed;
  top: calc(var(--letter-top) - 0.04em);
  right: calc(50% + var(--letter-measure) / 2 + 1.6em);
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.12em;
  /* The margin as it is at this width: never past the page's own side gutter. */
  width: min(calc(var(--letter-margin) - 1.6em), calc(50% - var(--letter-measure) / 2 - 1.6em - max(24px, var(--border) * 1.5)));
  max-height: calc(100svh - var(--letter-top) - var(--border) - var(--names-height, 70px) - 56px);
  overflow-y: auto;
  scrollbar-width: none;
  color: color-mix(in srgb, var(--layer-ink) 58%, transparent);
  font-size: calc(var(--letter-size) * 0.84);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.01em;
  animation: letter-contents-in 900ms cubic-bezier(0.33, 0, 0.2, 1) 280ms backwards;
}
.letter-contents .bridge-button[aria-current] {
  color: var(--layer-ink);
}
.letter-contents .bridge-button:hover {
  color: var(--layer-ink);
}
.letter-contents .bridge-button {
  margin: 0;
  padding: 0.06em 0.32em 0.12em;
  max-width: 100%;
  font-weight: 400;
  text-align: right;
  text-wrap: balance;
  --bridge-fill: var(--layer-2);
  --bridge-on: var(--layer-2-ink);
}
.letter-contents[hidden] {
  display: none;
}
@keyframes letter-contents-in {
  from {
    opacity: 0;
  }
}
@media (max-width: 1179.98px) {
  .letter-contents {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .letter-contents {
    animation: none;
  }
}
/* Solid only behind the corner words themselves (one top-right word; the page names, whose height
   src/ui/page-nav.js gives as --names-height), then a short fade, so as much text shows as can. */
.letter::before,
.letter::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  z-index: 6;
  pointer-events: none;
}
.letter::before {
  top: 0;
  height: calc(var(--border) + 78px);
  background: linear-gradient(to bottom, var(--layer-0) calc(var(--border) + 40px), transparent);
}
.letter::after {
  bottom: 0;
  height: calc(var(--border) + var(--names-height, 70px) + 44px);
  background: linear-gradient(to top, var(--layer-0) calc(var(--border) + var(--names-height, 70px) + 6px), transparent);
}
