/* Stitches and Visas: the green copy of a travel form, with a stamp-ink band and a pink copy for the references.
   Colours are Sanzo Wada no. 162 (Old Rose, Rainette Green, Lilac) with lightness moved per role; see DESIGN.md. */
:root {
  --ground: #d7e9b7;      /* Rainette Green L90: the paper */
  --ink: #213107;         /* Rainette Green L18: text and frames, 10.77:1 on the ground */
  --dim: #4a5a2f;         /* Rainette Green L36: labels, list dates, leads in lists, 5.81:1 */
  --rule: #718255;        /* Rainette Green L52: inner field and table rules, never text */
  --rule-faint: #a6b787;  /* Rainette Green L72: separators between rows, never text */
  --stamp: #993849;       /* Old Rose L38: masthead, footer, table heads, the entry stamp, links (5.38:1) */
  --on-stamp: #d7e9b7;    /* the paper reversed out of the stamp ink, 5.38:1 */
  --stamp-deep: #822337;  /* Old Rose L30: links on the pink copy, 5.48:1 */
  --copy: #edb5e2;        /* Lilac L80: the pink copy (short answers, references); ink on it 8.17:1 */
  --copy-dim: #6a3b63;    /* Lilac L32: numbers and accessed dates on the copy, 5.09:1 */
  --copy-rule: #af7ba5;   /* Lilac L58: rules on the copy, never text */

  --font-display: "Libre Baskerville", Baskerville, "Baskerville Old Face", "Hoefler Text", Georgia, serif;
  --font-text: "Schibsted Grotesk", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --font-ui: "IBM Plex Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;

  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2.25rem;
  --s7: 3.5rem;
  --s8: 5rem;

  --page: 72rem;
  --edge: clamp(1.125rem, 4vw, 3rem);
  --inset: max(var(--edge), calc((100% - var(--page)) / 2));
  --measure: 36rem;       /* 64 to 70 characters of Schibsted Grotesk at 18px, 68 to 72 in the fallback faces */
  --stub: 16rem;
  --gap: clamp(2.5rem, 5vw, 5rem);
  --frame: 1.5px solid var(--ink);

  --base: clamp(1.0625rem, 1.02rem + 0.2vw, 1.125rem);
  --lead: clamp(1.1875rem, 1.1rem + 0.4vw, 1.3125rem);
  --h1: clamp(2rem, 1.35rem + 2.6vw, 3rem);
  --h1-home: clamp(1.625rem, 1.15rem + 2.2vw, 2.75rem);
  --h2: clamp(1.25rem, 1.15rem + 0.45vw, 1.4375rem);
  --cell: 0.9375rem;
  --label: 0.8125rem;
  --typed: 0.875rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: var(--s5); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--base)/1.6 var(--font-text);
  overflow-wrap: break-word;
  font-synthesis: none;
  /* <main> is first in the document; the grid draws the masthead and the section row above it. */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "mast" "sections" "main" "foot";
}
main { grid-area: main; min-width: 0; padding: var(--s7) var(--inset) var(--s8); }
.mast { grid-area: mast; }
.sections { grid-area: sections; }
.foot { grid-area: foot; }

a { color: var(--stamp); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }
::selection { background: var(--copy); color: var(--ink); }
h1, h2, h3 { margin: 0; }
em { font-style: normal; color: var(--stamp-deep); }
strong, b { font-weight: 700; }

/* Masthead: a band of stamp ink across the top of every page. */
.mast { background: var(--stamp); color: var(--on-stamp); }
.mast-in {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: var(--s2) var(--s5);
  padding: var(--s4) var(--inset) 0.9rem;
}
.mast a { color: var(--on-stamp); }
.mast :focus-visible, .foot :focus-visible { outline-color: var(--on-stamp); }
.name { font: 700 1.375rem/1.1 var(--font-display); text-decoration: none; }
.name:hover { text-decoration: underline; text-decoration-thickness: 1px; }
.mast-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); font-size: 0.9375rem; line-height: 1.3; }
.mast-links a { text-decoration: none; }
.mast-links a:hover, .mast-links a[aria-current] { text-decoration: underline; }

/* Section row: the sections as one row of form fields with their counts typed in. */
.sections { padding: 0 var(--inset); border-bottom: var(--frame); }
.sections ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.sections li { display: flex; flex-direction: column; gap: 0.15rem; padding: var(--s3) var(--s4); border-left: 1px solid var(--rule); }
.sections li:first-child { border-left: 0; padding-left: 0; }
.sections a { font-weight: 600; font-size: 0.9375rem; line-height: 1.25; color: var(--ink); text-decoration: none; }
.sections a:hover, .sections a[aria-current] { color: var(--stamp); text-decoration: underline; }
.sections .n { font: var(--label)/1.3 var(--font-ui); color: var(--dim); }

/* Headline and lead, printed at the top of the form. */
.entry > h1, .opening h1 { font: 400 var(--h1)/1.16 var(--font-display); letter-spacing: -0.015em; text-wrap: balance; }
.opening-home h1 { font-size: var(--h1-home); line-height: 1.24; max-width: 23em; letter-spacing: -0.01em; }
.lead { margin: var(--s5) 0 0; max-width: var(--measure); font-size: var(--lead); line-height: 1.45; text-wrap: pretty; }
.opening { margin-bottom: var(--s6); }
.go { margin: var(--s5) 0 0; }

/* An entry: the reading column on the left, the stub on the right. */
.entry { display: grid; grid-template-columns: minmax(0, var(--measure)) var(--stub); column-gap: var(--gap); align-items: start; }
.entry > * { grid-column: 1; min-width: 0; }
.entry > h1 { grid-column: 1 / -1; max-width: 20em; }
.entry > .stub { grid-column: 2; grid-row: 2 / span 2; position: sticky; top: var(--s5); max-height: calc(100vh - 3rem); overflow-y: auto; margin-top: var(--s5); }
.entry > .answers, .entry > .refs, .entry > .related { grid-column: 1 / -1; }
.entry-page { display: block; }

/* Field box: label printed small, value typed. */
.fields { margin: 0; border: var(--frame); display: grid; grid-template-columns: minmax(0, 1fr); }
.field { padding: var(--s2) var(--s3) 0.65rem; min-width: 0; }
.field + .field { border-top: 1px solid var(--rule); }
.field dt { font-size: var(--label); line-height: 1.3; color: var(--dim); }
.field dd { margin: 0.2rem 0 0; font-size: var(--cell); line-height: 1.35; font-weight: 600; }
.field dd a { color: var(--ink); }
.field dd a:hover { color: var(--stamp); }
.field .typed { font: 400 var(--typed)/1.4 var(--font-ui); }
.stamp {
  display: inline-block; margin: 0.45rem 0 0.2rem 0.15rem; padding: 0.3rem 0.55rem 0.25rem;
  border: 2px solid var(--stamp); outline: 1px solid var(--stamp); outline-offset: 2px;
  color: var(--stamp); font: 700 var(--label)/1.2 var(--font-ui); text-transform: uppercase;
  transform: rotate(-1.5deg); white-space: nowrap;
}

/* Contents: the questions of the brief. */
.contents { margin-top: var(--s5); }
.contents-label { margin: 0 0 var(--s2); font: 700 1rem/1.3 var(--font-display); }
.contents ol { margin: 0; padding: 0 0 0 1.75rem; font-size: 0.9375rem; line-height: 1.35; }
.contents li { padding: 0.3rem 0; }
.contents li::marker { font-family: var(--font-ui); font-size: var(--label); color: var(--dim); }
.contents a { color: var(--ink); text-decoration: none; }
.contents a:hover { color: var(--stamp); text-decoration: underline; }

/* The brief. */
.body { max-width: var(--measure); margin-top: var(--s6); }
.body > * { margin: 0; }
.body > * + * { margin-top: var(--s4); }
.body p { text-wrap: pretty; }
.body h2 { margin-top: var(--s7); font: 700 var(--h2)/1.3 var(--font-display); text-wrap: balance; }
.body h3 { margin-top: var(--s6); font: 700 1.0625em/1.35 var(--font-text); }
.body h2 + *, .body h3 + * { margin-top: var(--s3); }
.body ul, .body ol { padding-left: 1.4rem; }
.body li + li { margin-top: var(--s2); }
.body ul > li::marker { color: var(--stamp); }
.body ol > li::marker { font-family: var(--font-ui); font-size: 0.875em; color: var(--stamp); }
.body blockquote { margin-left: 0; padding: var(--s1) 0 var(--s1) var(--s4); border-left: 3px solid var(--stamp); }
.body hr { border: 0; border-top: 2px dotted var(--rule); margin: var(--s6) 0; }
.body code { font: 0.875em var(--font-ui); }
.body img { max-width: 100%; height: auto; }

/* Visit tables: a printed form grid with a stamp-ink header row; it scrolls inside its own frame on a phone. */
.body table {
  display: block; width: fit-content; max-width: 100%; overflow-x: auto;
  margin-top: var(--s5); border: var(--frame); border-collapse: collapse;
  font-size: var(--cell); line-height: 1.45;
}
.body th, .body td { text-align: left; vertical-align: top; padding: 0.55rem 0.8rem 0.6rem; min-width: 6.5rem; border-left: 1px solid var(--rule); border-top: 1px solid var(--rule); }
.body tr > :last-child:not(:first-child) { min-width: 13rem; }   /* the column that says what happens keeps a readable width; on a phone the table scrolls instead */
.body tr > :first-child { border-left: 0; }
.body thead th { background: var(--stamp); color: var(--on-stamp); font-weight: 600; border-top: 0; border-left-color: var(--on-stamp); }
.body tbody tr:first-child > * { border-top: 0; }
.body tbody td:first-child { font-weight: 600; }
.body table + * { margin-top: var(--s5); }

/* The pink copy: short answers and references, torn off along a perforation. */
.answers, .refs { margin-top: var(--s7); padding: var(--s5) clamp(1.125rem, 3vw, 2.25rem) var(--s6); background: var(--copy); color: var(--ink); border-top: 5px dotted var(--ground); }
.answers + .refs { margin-top: 0; border-top: 1px solid var(--copy-rule); }
.answers h2, .refs h2, .related h2 { margin: 0 0 var(--s4); font: 700 1.1875rem/1.3 var(--font-display); }
.answers details { max-width: var(--measure); border-top: 1px solid var(--copy-rule); padding: var(--s3) 0; }
.answers details:last-of-type { border-bottom: 1px solid var(--copy-rule); }
.answers summary { cursor: pointer; font-weight: 600; line-height: 1.4; }
.answers summary::marker { color: var(--stamp-deep); }
.answers summary:hover { color: var(--stamp-deep); }
.answers details p { margin: var(--s2) 0 var(--s1); }
.refs ol { margin: 0; padding: 0; list-style: none; counter-reset: ref; columns: 2 21rem; column-gap: var(--gap); font-size: var(--cell); line-height: 1.45; }
.refs li { counter-increment: ref; break-inside: avoid; position: relative; padding: 0 0 var(--s3) 2.25rem; }
.refs li::before { content: counter(ref); position: absolute; left: 0; top: 0.05rem; font: var(--typed)/1.45 var(--font-ui); color: var(--copy-dim); }
.refs .pub { font-weight: 600; }
.refs a { color: var(--stamp-deep); }
.refs .read { display: block; font: var(--label)/1.45 var(--font-ui); color: var(--copy-dim); }

.related { margin-top: var(--s6); }
.related ul { margin: 0; padding: 0; list-style: none; max-width: 48rem; }
.related li { padding: var(--s2) 0; border-top: 1px solid var(--rule-faint); }
.related a { font: 400 1.0625rem/1.4 var(--font-display); color: var(--ink); text-decoration: none; }
.related a:hover { color: var(--stamp); text-decoration: underline; }

.revised { margin: var(--s4) 0 0; font: var(--typed)/1.4 var(--font-ui); color: var(--dim); }
.entry-page .body { margin-top: var(--s5); }

/* Lists of entries: the date typed in the stub column, the title printed beside it. */
.list-head { margin: var(--s7) 0 var(--s3); font: 700 1.1875rem/1.3 var(--font-display); }
.entries { list-style: none; margin: 0; padding: 0; max-width: 54rem; border-top: var(--frame); }
.entries li { display: grid; grid-template-columns: 10.5rem minmax(0, 1fr); gap: var(--s5); padding: var(--s4) 0 1.1rem; border-bottom: 1px solid var(--rule-faint); }
.entries time { font: var(--typed)/1.9 var(--font-ui); color: var(--dim); }
.entries a { font: 400 1.25rem/1.32 var(--font-display); color: var(--ink); text-decoration: none; }
.entries a:hover { color: var(--stamp); text-decoration: underline; }
.entries p { margin: var(--s2) 0 0; max-width: var(--measure); color: var(--dim); font-size: 0.9375rem; line-height: 1.5; }

.index { max-width: 58rem; }
.index-row { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: var(--s5); padding: var(--s4) 0; border-top: 1px solid var(--rule); }
.index .list-head + .index-row { border-top: var(--frame); }
.index-row h3 { font: 700 1.0625rem/1.35 var(--font-display); }
.index-row h3 a { color: var(--ink); text-decoration: none; }
.index-row h3 a:hover { color: var(--stamp); text-decoration: underline; }
.index-row ul { list-style: none; margin: 0; padding: 0; font-size: 0.9375rem; line-height: 1.4; }
.index-row li + li { margin-top: var(--s2); }
.index-row li a { color: var(--ink); text-decoration: none; }
.index-row li a:hover { color: var(--stamp); text-decoration: underline; }
.index-row .more a { color: var(--stamp); }

/* Footer: the stamp band again, closing the form. */
.foot { background: var(--stamp); color: var(--on-stamp); }
.foot-in { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--s3) var(--s6); padding: var(--s5) var(--inset) var(--s6); font-size: 0.875rem; line-height: 1.5; }
.foot-note { margin: 0; max-width: 34rem; }
.foot-links { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); }
.foot a { color: var(--on-stamp); }

/* Below the width that holds the reading column and the stub side by side. */
@media (max-width: 62rem) {
  body { grid-template-rows: auto 1fr auto auto; grid-template-areas: "mast" "main" "sections" "foot"; }
  main { padding-top: var(--s6); padding-bottom: var(--s7); }
  .sections { border-bottom: 0; border-top: var(--frame); padding-top: var(--s2); padding-bottom: var(--s6); }
  .sections ol { grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); column-gap: var(--s5); }
  .sections li, .sections li:first-child { padding: var(--s3) 0; border-left: 0; border-bottom: 1px solid var(--rule-faint); }
  .entry { display: block; }
  .entry > .stub { position: static; max-height: none; overflow: visible; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field + .field { border-top: 0; }
  .field:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .field:nth-child(even) { border-left: 1px solid var(--rule); }
  .field-stamp:last-child { grid-column: 1 / -1; }
  .answers, .refs { margin-left: calc(-1 * var(--edge)); margin-right: calc(-1 * var(--edge)); padding-left: var(--edge); padding-right: var(--edge); }
  .answers + .refs { margin-top: 0; }
  /* Touch targets of at least 44px for every link that is not inside a sentence. */
  .name, .mast-links a, .foot-links a, .field dd a { display: inline-block; min-width: 2.75rem; padding: 0.8rem 0; margin: -0.8rem 0; }
  .contents li { padding: 0; }
  .contents a, .sections a, .related a, .index-row li a { display: block; padding: 0.8rem 0; }
  .sections li, .sections li:first-child { padding: 0 0 var(--s3); }
  .sections .n { margin-top: -0.6rem; }
  .related li { padding: 0; }
  .index-row li + li { margin-top: 0; }
  .answers summary { padding: 0.35rem 0; }
}
@media (max-width: 40rem) {
  .entries li, .index-row { grid-template-columns: minmax(0, 1fr); gap: var(--s1); }
  .index-row { gap: var(--s2); }
  .mast-in { padding-top: 0.85rem; padding-bottom: 0.8rem; }
  .name { font-size: 1.25rem; }
  .mast-links { gap: var(--s1) var(--s4); font-size: 0.875rem; }
}
@media print {
  body { display: block; background: #fff; }
  .sections, .mast-links, .related { display: none; }
  .mast, .foot { background: none; color: var(--ink); }
  .mast a, .foot a { color: var(--ink); }
  .entry { display: block; }
  .entry > .stub { position: static; max-height: none; }
}

/* pictures in posts */
figure.photo { margin: 2em 0; }
figure.photo:first-child { margin-top: 0; }
figure.photo img { display: block; width: 100%; height: auto; box-shadow: 0 0 0 1px var(--rule-faint); }
