/* apie page styles. Owned by its builder. Prefix every class with .ap-
   Three text sizes: the Title (--t-2xl), the letter (--t-xl at 400) and labels (--t-xs). No Display, no dot.
   The default below is the phone: the letter in one column, each picture after its paragraph, the signed portrait last. */

.ap { padding-top: clamp(1.5rem, 7vw, 3rem); }
.ap-letter { isolation: isolate; }

.ap-title { margin-bottom: 3.5rem; }

/* the letter: large enough that the light can be followed word by word */
.ap-p { --ap-lh: 1.24; max-width: 30ch; font-size: var(--t-xl); font-weight: 400; line-height: var(--ap-lh); letter-spacing: -0.012em; text-wrap: balance; }
.ap-nb { white-space: nowrap; }
.ap-close .ap-p + .ap-p { margin-top: 0.8em; }
.ap-kit { max-width: 44ch; margin-top: 2.25rem; text-wrap: balance; }

/* pictures: edge to edge at their own ratio, text first and the picture after it */
/* a paragraph belongs to the picture that follows it: 2.5rem before the picture, 6.5rem after it, so the next
   paragraph can never be read as a caption under the picture above */
.ap-pic { margin: 2.5rem calc(var(--gut) * -1) 6.5rem; }
.ap-pic .ph { width: 100%; aspect-ratio: var(--r); }
/* the signed portrait closes the letter; the footer starts after a clear pause, not directly under the photograph */
.ap-pic--me { margin-bottom: 5rem; }

/* the album a picture comes from, inside its corner; it leads to that album */
.ap-cap { text-decoration: none; }
.ap-cap::after { content: ""; position: absolute; inset: -0.875rem -0.875rem 0 0; }
/* the underline is drawn by a transform, on pointers that can hover */
.ap-cap::before { content: ""; position: absolute; left: 0.75rem; right: 0.75rem; bottom: 0.45rem; height: 1px; background: currentColor; transform: scaleX(0); transform-origin: 0 50%; transition: transform var(--d-fast) var(--out); }
@media (hover: hover) and (pointer: fine) { .ap-cap:hover::before, .ap-cap:focus-visible::before { transform: scaleX(1); } }
.ap-cap:focus-visible { outline-offset: -3px; }
@media (pointer: coarse) { .ap-cap { display: flex; align-items: center; min-height: 2.75rem; padding-inline: 0.875rem; } }

/* the signature: his wordmark, untouched, written into the portrait's lower left corner */
.ap-pic .ap-sign { position: absolute; left: 6.5%; bottom: 6%; z-index: 2; width: clamp(6.5rem, 38%, 13.5rem); height: auto; object-fit: contain; opacity: 1; transition: none; }

/* between phone and desk: pictures keep to the column and never grow taller than the screen */
@media (min-width: 36rem) and (max-width: 51.99rem) {
  .ap-pic { margin-inline: 0; width: min(100%, calc(74svh * var(--r))); }
}

/* wide: the letter runs down columns 1 to 6; every picture takes the same area in columns 8 to 12 and sticks there,
   so together they are one frame that holds while the whole letter passes */
@media (min-width: 52rem) {
  .ap { padding-top: 1rem; padding-bottom: var(--sec); }
  .ap-letter {
    /* the frame: five columns wide, 3:4, never taller than the screen under the header */
    --ap-fw: min(calc((min(100vw - 2 * var(--gut), var(--wrap)) - 16.5rem) * 5 / 12 + 6rem), calc((100svh - var(--top-h) - 2rem) * 0.75));
    --ap-fh: calc(var(--ap-fw) * 4 / 3);
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 1.5rem;
    /* the first screen is the Title and the portrait; the letter's first line waits at its lower edge */
    grid-template-rows: minmax(calc(100svh - var(--top-h) - 2.75rem - 3 * 1.24 * var(--t-xl)), auto);
  }
  /* he looks left, toward the words: the Title is centred on his eye line (39% down the portrait) */
  .ap-title { grid-column: 1 / 8; grid-row: 1; align-self: start; margin: max(1rem, calc(var(--ap-fh) * 0.39 - 2.2em)) 0 3rem; }

  .ap-part { grid-column: 1 / 7; grid-row: var(--row); }
  .ap-part--story { min-height: 62vh; }

  .ap-pic { grid-column: 8 / 13; grid-row: 1 / span 5; position: sticky; top: calc(var(--top-h) + 1rem); z-index: 1; align-self: start; justify-self: end; width: min(100%, var(--ap-fw)); aspect-ratio: 3 / 4; margin: 0; }
  .ap-pic .ph { height: 100%; aspect-ratio: auto; }
  .ap-pic--me { z-index: 2; }
}
