/* Writing. The first screen and the list of posts, a sample of how a post is laid out, and the dark panel that
   ends on the door. Built from the kit in site.css. What is here is what the kit lacks: the post layout with
   its sources in the margin, the headline that sharpens as the page moves, and the door that grows out of the
   dark panel into the last screen.
   A real post uses the .wr-post classes too. Its sources go in .wr-sources and each footnote is a .wr-ref. */

/* ---------- first screen ---------- */
/* The board gives the words the wider side here, and the photograph a tall slice of the right edge. */
.wr-top { grid-template-columns: minmax(0, 7fr) minmax(0, 4.6fr); }
.wr-down:hover i { translate: 0 4px; }
/* The caption comes up under the pointer. Where there is no pointer it is always there. */
.wr-pic figcaption { position: absolute; left: 14px; bottom: calc(4vw + 14px); max-width: calc(100% - 4vw - 28px); line-height: 1.35; white-space: normal; opacity: 0; translate: 0 6px; transition: opacity 0.25s, translate 0.4s var(--out); }
.wr-pic:hover figcaption, .wr-top:focus-within .wr-pic figcaption { opacity: 1; translate: 0 0; }
@media (hover: none) { .wr-pic figcaption { opacity: 1; translate: 0 0; } }

@media (prefers-reduced-motion: no-preference) {
  /* The photograph opens with a wipe from its right edge. */
  .wr-pic { animation: wr-wipe 0.8s var(--out) 0.1s backwards; }
}
@keyframes wr-wipe { from { clip-path: inset(0 0 0 100%); } to { clip-path: inset(0 0 0 0); } }

@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    /* The second half of the headline starts in grey and turns to ink a word at a time over the first 220px of
       scroll, while the headline is still on screen. --i is the word's place. Without this the headline is all ink. */
    .wr-h1 > span { animation: wr-sharpen linear both; animation-timeline: scroll(root block); animation-range: calc(var(--i) * 20px) calc(var(--i) * 20px + 80px); }
  }
}
@keyframes wr-sharpen { from { color: var(--stone); } }

/* ---------- the list of posts ---------- */
.wr-tell { width: min(100%, 27em); margin-top: clamp(10px, 1.6vw, 24px); }
.wr-tell .btn { justify-self: start; margin-top: 8px; font-family: var(--sans); }
/* A planned post: its number, its title, one sentence, and the word Planned where the date will go.
   A published post is the same row as a link, <a class="k-row" href="writing/its-file.html">, with its date in
   the last column, and it goes above the planned ones. */
.wr-posts .k-row { padding-block: clamp(14px, 1.3vw, 20px); }
.wr-posts .k-row b { font-size: clamp(19px, 1.5vw, 25px); font-weight: 500; line-height: 1.1; letter-spacing: -0.022em; }
.wr-posts .k-row:hover { background: var(--raise); margin-inline: -12px; padding-inline: 12px; }

/* ---------- earlier issues ---------- */
/* The issues older than the seven rows, as short links. The import writes them and leaves this empty when there
   are none. */
.wr-earlier { display: grid; gap: 12px; margin-top: clamp(22px, 2.4vw, 36px); }
.wr-earlier:not(:has(a)) { display: none; }
.wr-earlier-list > a { --sq-r: 8px; min-height: 34px; padding: 0 10px; font: 500 12px/1 var(--mono); color: var(--body); }
.wr-earlier-list > a:hover { --sq-fill: var(--on); color: var(--on-fg); }

/* ---------- the story graph ---------- */
/* One square per story and one line per shared name. tools/newsletter/graph.mjs draws it into the page, and
   assets/graph.js lets a reader drag it. Every square is a grey. Age is the only thing the tone says: the newest
   day is darkest. Ink is kept for the story under the pointer and the day whose chip is chosen. */
.wr-graph { margin-top: var(--k-gap); padding-top: clamp(28px, 3.4vw, 52px); border-top: 1px solid var(--rule); }
/* Until the import has drawn a picture there is nothing to describe, so the whole part stays away. */
.wr-graph:not(:has(.wr-g, .wr-g-none)) { display: none; }
.wr-g { position: relative; display: grid; gap: 16px; }
.wr-g-svg { display: block; width: 100%; height: auto; aspect-ratio: 860 / 540; overflow: visible; touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.wr-g-links line { stroke: var(--rule); stroke-width: 1; vector-effect: non-scaling-stroke; transition: stroke 0.2s; }
.wr-g-links line.is-on { stroke: var(--ink); }
[data-age="0"] { --tone: var(--text); }
[data-age="1"] { --tone: var(--soft); }
[data-age="2"] { --tone: var(--stone); }
[data-age="3"] { --tone: var(--faint); }
[data-age="4"] { --tone: #A6A6AB; }
[data-age="5"] { --tone: #BCBCC1; }
[data-age="6"] { --tone: var(--fog); }
/* The clear stroke widens what a pointer or a finger can land on. It paints nothing. */
.wr-g-day rect { fill: var(--tone); stroke: transparent; stroke-width: 16px; pointer-events: all; transform-box: fill-box; transform-origin: center; transition: fill 0.2s, scale 0.25s var(--out); }
.wr-g-day a { cursor: grab; outline: none; }
.wr-g.is-held .wr-g-day a { cursor: grabbing; }
.wr-g-day a:hover rect, .wr-g-day a.is-on rect { fill: var(--ink); scale: 1.7; }
.wr-g-day a.is-near rect { fill: var(--ink); }
.wr-g[data-show] .wr-g-day:not(.is-on) rect { fill: var(--fog); }
.wr-g[data-show] .wr-g-day.is-on rect { fill: var(--ink); }
/* The plate that names the story under the pointer. --px and --py are the square's place in the figure. */
.wr-g-plate { --sq-r: 9px; --sq-fill: var(--ink); position: absolute; left: 0; top: 0; z-index: 2; display: grid; gap: 5px; width: max-content; max-width: min(320px, 86%); padding: 9px 12px 10px; color: #fff; pointer-events: none; translate: calc(var(--px, 0px) - 50%) calc(var(--py, 0px) - 100%); }
.wr-g-plate[hidden] { display: none; }
.wr-g-plate.is-under { translate: calc(var(--px, 0px) - 50%) calc(var(--py, 0px) + 50px); }
.wr-g-plate b { font: 500 14px/1.22 var(--sans); letter-spacing: -0.01em; }
.wr-g-plate small { font: 400 11px/1.35 var(--mono); color: #C7C7CC; }
.wr-g-plate.is-pinned { pointer-events: auto; }
.wr-g-plate a { justify-self: start; min-height: 44px; margin-bottom: -8px; display: inline-flex; align-items: center; font: 500 14px/1 var(--sans); color: #fff; }
/* The seven issues under the picture. Each chip opens its issue, and while it is hovered or focused its stories
   are the ones in ink. The small square is the tone that day's stories are drawn in. */
.wr-g-days > a { min-height: 40px; padding: 0 12px; font: 500 13px/1 var(--mono); }
.wr-g-days > a:hover, .wr-g-days > a:focus-visible { --sq-fill: var(--on); color: var(--on-fg); }
.wr-g-days small { font: inherit; color: var(--label); }
.wr-g-days > a:hover small, .wr-g-days > a:focus-visible small { color: inherit; }
.wr-g-key { flex: none; width: 9px; height: 9px; background: var(--tone); }
/* Dragging needs script, so the line that offers it shows only when script runs. */
html:not(.js) .wr-g-how { display: none; }

/* ---------- a post ---------- */
/* Three columns: what the post is in the left margin, the reading column, and each source in the right margin
   level with the paragraph it supports. */
.wr-post { display: grid; grid-template-columns: minmax(0, 2.4fr) minmax(0, 6fr) minmax(0, 3.6fr); column-gap: clamp(24px, 4vw, 72px); align-items: start; }
.wr-post-meta { grid-column: 1; grid-row: 1 / span 2; display: grid; gap: 14px; padding-top: 0.5em; }
.wr-post-pin { grid-column: 3; grid-row: 1; justify-self: end; white-space: normal; line-height: 1.35; }
.wr-post-title { grid-column: 2; grid-row: 1; }
.wr-post-deck { grid-column: 2; grid-row: 2; margin-top: clamp(20px, 2.6vw, 40px); font-size: clamp(19px, 1.5vw, 25px); line-height: 1.3; letter-spacing: -0.012em; color: var(--ink); }
.wr-post-text { grid-column: 2; grid-row: 3; margin-top: clamp(14px, 1.6vw, 24px); }
.wr-sources { grid-column: 3; grid-row: 3; margin-top: clamp(18px, 2vw, 30px); }
.wr-take { grid-column: 2; grid-row: 4; max-width: 40em; margin-top: clamp(28px, 3.4vw, 52px); }

/* A footnote number. The number is small, so the place a finger or a pointer can land runs well past it. */
.wr-ref { position: relative; color: var(--ink); }
.wr-ref::after { content: ''; position: absolute; inset: -17px -14px; }
/* The source whose card is showing sits on the brighter surface, as a source does when a link has gone to it. */
.wr-sources > li { position: relative; transition: background-color 0.2s; }
.wr-sources > li.is-on { background: var(--raise); margin-inline: -12px; padding-inline: 12px; color: var(--ink); }
.wr-sources a { display: inline-block; padding-block: 6px; margin-block: -6px; color: var(--ink); }
.wr-src { touch-action: pan-y; }

/* The checklist a reader takes away. The sheet lies square in the reading column. */
.wr-take { --tilt: 0deg; }
.wr-take .k-doc-head { align-items: center; }
.wr-take .k-doc-rows { --cols: minmax(0, 1fr); }
.wr-copy { min-height: 44px; margin: -14px -10px; padding: 0 10px; font: 500 12px/1.2 var(--mono); color: var(--ink); }

@media (min-width: 900px) {
  /* A hairline runs from the reading column to each source. */
  .wr-sources > li::after { content: ''; position: absolute; right: 100%; top: -1px; width: clamp(24px, 4vw, 72px); height: 1px; background: var(--rule); transform-origin: 0 50%; }
}

/* ---------- from reading to a call ---------- */
/* --dw and --dh are the size of the small door in the dark panel. The door band reads them too, because its
   picture starts out as that small door. */
.wr-ask, .wr-door { --dw: clamp(260px, 34vw, 571px); --dh: calc(var(--dw) * 24 / 34); }
.wr-ask-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: clamp(24px, 4vw, 72px); row-gap: clamp(28px, 3.6vw, 56px); align-items: end; }
.wr-ask-grid > h2 { grid-column: 1 / -1; max-width: 12.5em; }
.wr-ask-words { --gap: clamp(18px, 2vw, 30px); align-self: start; }
.wr-ask-words .k-note a { display: inline-block; padding-block: 14px; margin-block: -14px; }
/* The door, close up: the same picture as the last screen, moved in on the doorway. */
.wr-ask-pic { --sq-r: 22px; --ar: 34 / 24; --at: 100% 50%; width: var(--dw); }
.wr-ask-pic > img { scale: 1.5; transform-origin: 75% 40%; }

/* The corner of the door picture as it grows. Registered so it can run from 22px to none. */
@property --wr-r { syntax: '<length>'; inherits: true; initial-value: 0px; }
/* The picture inside is scaled up while the window is small, and what runs past the window must not widen the page. */
.wr-door .k-band-pic { --sq-r: var(--wr-r); overflow: clip; }

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* These move and never fade, so what has not been scrolled to yet is still there to read, print or capture. */
    .wr-posts .k-row, .wr-take { animation: wr-rise linear both; animation-timeline: view(); animation-range: entry 0% entry 100%; }
    .wr-take { animation-name: wr-sheet; animation-range: entry 0% entry 70%; }
  }
  @media (prefers-reduced-motion: no-preference) and (min-width: 900px) {
    .wr-sources > li::after { animation: wr-draw linear both; animation-timeline: view(); animation-range: entry 100% cover 32%; }
  }
  /* The growing window. Until the last screen comes into view its picture sits in the dark panel as the small
     door. As the screen rises the picture grows down and left until it fills it. Where this cannot run, the dark
     panel shows a small door of its own and the last screen is the plain kit door. */
  @media (prefers-reduced-motion: no-preference) and (min-width: 1000px) and (min-aspect-ratio: 5/6) {
    .wr-ask-pic { visibility: hidden; }
    .wr-door { overflow: visible; view-timeline: --wr-door block; }
    .wr-door .k-band-pic { --dr: max(var(--m), (100% - var(--k-max)) / 2); animation: wr-grow linear both; animation-timeline: --wr-door; animation-range: entry 0% entry 100%; }
    .wr-door .k-band-pic > img { transform-origin: 75% 40%; animation: wr-zoom linear both; animation-timeline: --wr-door; animation-range: entry 0% entry 100%; }
  }
}
@keyframes wr-rise { from { translate: 0 18px; } }
@keyframes wr-sheet { from { translate: 0 48px; } }
@keyframes wr-draw { from { scale: 0 1; } }
@keyframes wr-grow {
  from { top: calc(-1 * (var(--k-gap) + var(--dh))); bottom: calc(100% + var(--k-gap)); left: calc(100% - var(--dr) - var(--dw)); right: var(--dr); --wr-r: 22px; }
  to { top: 0; bottom: 0; left: 0; right: 0; --wr-r: 0px; }
}
@keyframes wr-zoom { from { scale: 1.5; object-position: 100% 50%; } to { scale: 1; object-position: 70% 50%; } }

/* ---------- narrower ---------- */
@media (max-width: 999px) {
  /* The last screen follows at once, so the dark panel does not show the door twice. */
  .wr-ask-grid { grid-template-columns: minmax(0, 1fr); }
  .wr-ask-pic { display: none; }
}

@media (max-width: 899px) {
  /* One reading column. Each source follows the paragraph it supports. */
  .wr-post { grid-template-columns: minmax(0, 1fr); }
  .wr-post > * { grid-column: auto; grid-row: auto; }
  .wr-post-meta { grid-auto-flow: column; justify-content: start; align-items: baseline; gap: 4px 1.4em; padding-top: 0; }
  .wr-post-pin { justify-self: start; margin-block: 14px 18px; }
  .wr-sources a { padding-block: 14px; margin-block: -14px; }
}

/* A phone or an upright tablet. The photograph is a band at the top, so its caption sits on the band's own edge. */
@media (max-width: 699px), (max-aspect-ratio: 41/50) {
  .wr-pic figcaption { left: 12px; bottom: 12px; max-width: calc(100% - 24px); }
}

@media (max-width: 699px) {
  /* A phone gets a taller box, and graph.js settles the squares into it. With script off the picture keeps the
     shape it was drawn in. */
  html.js .wr-g-svg { aspect-ratio: 4 / 5; }
  .wr-earlier-list > a, .wr-g-days > a { min-height: 44px; }
  .wr-tell { width: 100%; }
  .wr-tell .btn { justify-self: stretch; min-height: 56px; font-size: 17px; }
  .wr-posts .k-row > span, .wr-posts .k-row > small:last-child { grid-column: 2; }
  .wr-post-meta { grid-auto-flow: row; }
}

@media (prefers-reduced-motion: reduce) {
  .wr-pic figcaption, .wr-sources > li, .wr-g-day rect, .wr-g-links line { transition-duration: 0.01s; }
}
