/* Downtime Journal: a printed timetable leaflet. See DESIGN.md.
   Colours: Wada combination 261 (Red, Pale Lemon Yellow, Calamine Blue, Warm Gray), lightness moved only for contrast. */
:root {
  --ground: #ffefae;    /* Pale Lemon Yellow: the stock */
  --ink: #2d2f27;       /* Warm Gray at L 0.30: running text, 11.77:1 on the ground */
  --dim: #55564e;       /* Warm Gray at L 0.45: dates, publishers, 6.44:1 */
  --route: #a72144;     /* Red: band, route line, headlines, 6.19:1 on the ground */
  --on-route: #ffefae;  /* the stock reversed out of the red, 6.19:1 */
  --tint: #78cdd0;      /* Calamine Blue: table heads, sources, colophon; ink on it 7.39:1 */
  --stripe: #f5e5a4;    /* Pale Lemon Yellow at L 0.92: alternate rows; ink 10.74:1, dim 5.88:1 */
  --link: #006366;      /* Calamine Blue at L 0.45: links on the stock, 6.12:1 (never on the tint) */
  --rule: #a1a39a;      /* Warm Gray: column rules only, never text */

  --font-display: "Young Serif", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-text: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ui: "Archivo", "Helvetica Neue", Arial, "Segoe UI", Roboto, sans-serif;

  /* one spacing scale */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 1rem;
  --s4: 1.5rem;
  --s5: 2.5rem;
  --s6: 4rem;

  --page: 76rem;
  --edge: clamp(1rem, 4.5vw, 2.5rem);
  --stub: 13rem;        /* the stop-name column: dates, topic, contents */
  --gap: 2.5rem;
  --measure: 30em;      /* of running text: 62 to 70 characters of Atkinson a line, measured */
  --line: 3px;          /* the route line */
  --stop: 13px;         /* a stop on it */

  --t-small: 0.875rem;
  --t-table: 0.9375rem;
  --t-body: clamp(1.0625rem, 1.03rem + 0.15vw, 1.125rem);
  --t-lead: clamp(1.2rem, 1.1rem + 0.45vw, 1.375rem);
  --t-h3: clamp(1.15rem, 1.1rem + 0.25vw, 1.25rem);
  --t-h2: clamp(1.4rem, 1.25rem + 0.6vw, 1.65rem);
  --t-h1: clamp(2.05rem, 1.45rem + 2.5vw, 3.1rem);
  --t-front: clamp(3.1rem, 1.6rem + 6vw, 5.25rem);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--ground); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font: var(--t-body)/1.62 var(--font-text);
  overflow-wrap: break-word;
}
::selection { background: var(--tint); color: var(--ink); }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { color: var(--route); text-decoration-thickness: 2px; }
a:active { color: var(--ink); }
:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; font-variant-numeric: lining-nums; text-wrap: balance; }
time { font-variant-numeric: tabular-nums; }

/* ---------- Route band: after <main> in the document, first on screen ---------- */
.band { order: -1; background: var(--route); color: var(--on-route); }
.band-inner {
  width: min(100% - 2 * var(--edge), var(--page));
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s2) var(--s5);
  padding: var(--s3) 0;
}
.band a { color: var(--on-route); text-decoration: none; }
.band a:hover { text-decoration: underline; text-decoration-thickness: 2px; }
.band :focus-visible { outline-color: var(--on-route); }
.wordmark { font: 400 1.6rem/1 var(--font-display); white-space: nowrap; }
.routes { flex: 1 1 30rem; min-width: 0; }
.routes ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  margin: 0;
  padding: 0;
  list-style: none;
  font: 400 var(--t-table)/1.5 var(--font-ui);
}
.routes li { white-space: nowrap; }
.routes .house { margin-left: auto; }
.routes a[aria-current] { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 0.35em; }
.home .wordmark { display: none; }

/* ---------- Main ---------- */
main { flex: 1 0 auto; width: 100%; padding-bottom: var(--s6); }
.piece, .listing, .lead-story, .river {
  width: min(100% - 2 * var(--edge), var(--page));
  margin-inline: auto;
}
.piece, .listing { padding-top: clamp(var(--s5), 5vw, var(--s6)); }

h1 { font-size: var(--t-h1); line-height: 1.08; letter-spacing: -0.015em; color: var(--route); margin: 0 0 var(--s3); max-width: 20em; }
.standfirst {
  font: 400 var(--t-lead)/1.42 var(--font-display);
  font-variant-numeric: lining-nums;
  max-width: 30em;
  margin: 0;
  text-wrap: pretty;
}
.dateline {
  font: 400 var(--t-small)/1.45 var(--font-ui);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  margin: var(--s3) 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--s3);
}
.dateline .topic, .index .topic { color: var(--route); font-weight: 700; text-decoration: none; }
.dateline .topic:hover, .index .topic:hover { text-decoration: underline; }

/* Contents: a calamine box on a phone, a list in the stub column on a wide screen */
.contents {
  margin: var(--s4) 0 0;
  padding: var(--s3) var(--s4);
  background: var(--tint);
  font: 400 var(--t-small)/1.4 var(--font-ui);
}
.contents p { margin: 0 0 var(--s2); font-weight: 700; }
.contents ol { margin: 0; padding-left: 1.6rem; font-variant-numeric: tabular-nums; }
.contents li + li { margin-top: var(--s1); }
.contents a { color: var(--ink); text-decoration: none; }
.contents a:hover { text-decoration: underline; color: var(--ink); }
.contents li::marker { font-weight: 700; }

/* ---------- Prose and the route line ---------- */
.prose { margin-top: var(--s5); }
.prose > * { max-width: var(--measure); margin-top: 0; margin-bottom: 0; }
.prose > * + * { margin-top: 1em; }
.prose p { text-wrap: pretty; }
.prose h2 { font-size: var(--t-h2); line-height: 1.18; color: var(--route); max-width: 22em; margin-top: var(--s5); }
.prose h3 { font-size: var(--t-h3); line-height: 1.25; max-width: 28em; margin-top: var(--s4); }
.prose h2 + *, .prose h3 + * { margin-top: var(--s2); }
.prose > :first-child { margin-top: 0; }
.prose strong { font-weight: 700; }
.prose ul, .prose ol { padding-left: 1.35rem; }
.prose ul { list-style: square; }
.prose li::marker { color: var(--route); }
.prose ol li::marker { font: 700 0.95em var(--font-ui); font-variant-numeric: tabular-nums; }
.prose li + li { margin-top: var(--s2); }
.prose li > ul, .prose li > ol { margin-top: var(--s2); }
.prose blockquote { margin-left: 0; margin-right: 0; padding: var(--s2) 0 var(--s2) var(--s3); border-left: 6px solid var(--tint); }
.prose blockquote > * { margin: 0; }
.prose blockquote > * + * { margin-top: 0.75em; }
.prose hr { border: 0; height: var(--line); width: 3rem; background: var(--route); margin: var(--s5) 0; }
.prose img { max-width: 100%; height: auto; }
.prose code { font-family: var(--font-ui); font-size: 0.92em; }

.route { position: relative; border-left: var(--line) solid var(--route); padding-left: var(--s3); padding-bottom: var(--s2); }
.route h2 { position: relative; }
.route h2::before {           /* the stop: a square sitting on the route line */
  content: "";
  position: absolute;
  left: calc(-1 * var(--s3) - var(--line) / 2 - var(--stop) / 2);
  top: calc(0.62em - var(--stop) / 2);
  width: var(--stop);
  height: var(--stop);
  background: var(--route);
}
.route::after {               /* terminus */
  content: "";
  position: absolute;
  left: calc(-1 * var(--line) - 6px);
  bottom: 0;
  width: 15px;
  height: var(--line);
  background: var(--route);
}

/* Tables: timetable panels */
.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font: 400 var(--t-table)/1.42 var(--font-ui);
  font-variant-numeric: tabular-nums;
  margin-top: var(--s4);
  margin-bottom: var(--s2);
}
.prose table + * { margin-top: var(--s4); }
.prose th, .prose td { text-align: left; vertical-align: top; padding: 0.55rem 0.8rem; min-width: 7rem; }
.prose th { background: var(--tint); font-weight: 700; vertical-align: bottom; line-height: 1.3; }
.prose th + th, .prose td + td { border-left: 1px solid var(--rule); }
.prose th + th { border-left-color: var(--ink); border-left-color: color-mix(in srgb, var(--ink) 35%, var(--tint)); }
.prose tbody tr:nth-child(even) td { background: var(--stripe); }
.prose tbody tr:last-child td { border-bottom: var(--line) solid var(--route); }
.prose td a { color: var(--link); }

/* Questions, outside the route */
.questions { margin-top: var(--s6); max-width: 34rem; }
.questions h2 { font-size: var(--t-h2); line-height: 1.18; color: var(--route); margin: 0; }
.questions dl { margin: 0; }
.questions .qa { margin-top: var(--s4); }
.questions dt { font: 400 var(--t-h3)/1.3 var(--font-display); font-variant-numeric: lining-nums; }
.questions dd { margin: var(--s2) 0 0; }

/* Sources: the notes panel under the timetable */
.sources {
  margin-top: var(--s5);
  max-width: 34rem;
  padding: var(--s4);
  background: var(--tint);
  color: var(--ink);
  font: 400 var(--t-table)/1.45 var(--font-ui);
}
.sources h2 { font: 700 1rem/1.2 var(--font-ui); margin: 0 0 var(--s3); }
.sources ol { list-style: none; margin: 0; padding: 0; counter-reset: note; }
.sources li {
  counter-increment: note;
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) auto;
  gap: 0 var(--s3);
  align-items: baseline;
}
.sources li + li { margin-top: var(--s2); }
.sources li::before { content: counter(note); font-weight: 700; font-variant-numeric: tabular-nums; }
.sources a { color: var(--ink); text-decoration-thickness: 1px; }
.sources a:hover { color: var(--ink); text-decoration-thickness: 2px; }
.sources :focus-visible { outline-color: var(--ink); }
.sources .read { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Timetable index: front page, topic pages, archive, read next ---------- */
.index { list-style: none; margin: 0; padding: 0; }
.index > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "date topic" "entry entry";
  gap: var(--s1) var(--s3);
  padding: var(--s3) var(--s3);
  margin-inline: calc(-1 * var(--s3));
}
.index > li:nth-child(odd) { background: var(--stripe); }
.index > li > time { grid-area: date; font: 400 var(--t-small)/1.4 var(--font-ui); color: var(--dim); }
.index > li > .topic { grid-area: topic; font: 700 var(--t-small)/1.4 var(--font-ui); text-align: right; }
.index .entry { grid-area: entry; min-width: 0; }
.index .entry > a { font: 400 1.3rem/1.22 var(--font-display); font-variant-numeric: lining-nums; color: var(--ink); text-decoration: none; text-wrap: balance; }
.index .entry > a:hover { color: var(--route); text-decoration: underline; text-decoration-thickness: 1px; }
.index .entry > p { margin: var(--s1) 0 0; color: var(--dim); font-size: 0.95rem; line-height: 1.5; max-width: var(--measure); }

.listing h1 { margin-bottom: var(--s3); }
.listing .standfirst { margin-bottom: var(--s5); }
.listing h1 + .index { margin-top: var(--s5); }
.more { margin-top: var(--s6); }
.more h2, .river > h2 { font-size: var(--t-h2); line-height: 1.18; color: var(--route); margin: 0 0 var(--s3); }
.all { font: 700 var(--t-small)/1.4 var(--font-ui); margin: var(--s4) 0 0; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); }
.all a { color: var(--route); }

/* ---------- Front page ---------- */
.front { background: var(--route); color: var(--on-route); }
.front-inner { width: min(100% - 2 * var(--edge), var(--page)); margin-inline: auto; padding: var(--s4) 0 var(--s6); }
.front h1 { font-size: var(--t-front); line-height: 0.98; letter-spacing: -0.02em; color: var(--on-route); margin: 0; max-width: 8em; }
.front-tagline { font: 400 var(--t-lead)/1.38 var(--font-display); max-width: 30em; margin: var(--s4) 0 0; }
.front-note { max-width: var(--measure); margin: var(--s3) 0 0; }
.lead-story { padding-top: var(--s5); padding-bottom: var(--s5); }
.lead-story h2 { font-size: var(--t-h1); line-height: 1.08; letter-spacing: -0.015em; margin: 0 0 var(--s3); max-width: 20em; }
.lead-story h2 a { color: var(--route); text-decoration: none; }
.lead-story h2 a:hover { text-decoration: underline; text-decoration-thickness: 2px; }

/* ---------- Colophon ---------- */
.colophon { background: var(--tint); color: var(--ink); font: 400 var(--t-small)/1.5 var(--font-ui); }
.colophon-inner { width: min(100% - 2 * var(--edge), var(--page)); margin-inline: auto; padding: var(--s5) 0 var(--s5); display: grid; gap: var(--s2) var(--gap); }
.colophon p { margin: 0; max-width: var(--measure); }
.colophon-name { font: 400 1.35rem/1.1 var(--font-display); }
.colophon ul { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); margin: var(--s2) 0 0; padding: 0; list-style: none; }
.colophon a { color: var(--ink); }
.colophon a:hover { color: var(--ink); text-decoration-thickness: 2px; }
.colophon :focus-visible { outline-color: var(--ink); }

/* ---------- Phone: topics run on one line that scrolls inside the band ---------- */
@media (max-width: 39.99rem) {
  .band-inner { gap: var(--s2) var(--s4); padding: var(--s3) 0 var(--s2); }
  .routes { flex-basis: 100%; margin-inline: calc(-1 * var(--edge)); }
  .routes ul { flex-wrap: nowrap; overflow-x: auto; padding: 0 var(--edge) var(--s2); scrollbar-width: thin; scrollbar-color: var(--on-route) var(--route); }
  .routes .house { margin-left: 0; }
  .home .band-inner { padding-top: var(--s2); }
  .sources, .contents { margin-inline: calc(-1 * var(--edge)); padding: var(--s4) var(--edge); }
  /* tap targets of at least 44px on a phone */
  .contents li + li { margin-top: 0; }
  .contents a { display: flex; align-items: center; min-height: 44px; }
  .routes a, .wordmark { display: inline-block; padding-block: 0.7rem; margin-block: -0.7rem; }
  .routes ul { padding-top: 0.7rem; padding-bottom: 0.7rem; margin-top: -0.2rem; }
  .dateline .topic, .index .topic { display: inline-block; padding-block: 0.8rem; margin-block: -0.8rem; }
  .colophon ul { gap: 0 var(--s4); }
  .colophon li a { display: inline-block; padding-block: 0.75rem; }
  .all a { display: inline-block; padding-block: 0.8rem; margin-block: -0.8rem; }
  .routes a, .colophon li a, .index .topic, .dateline .topic { min-width: 44px; }
  .index > li { margin-inline: calc(-1 * var(--edge)); padding-inline: var(--edge); }
  .sources li { grid-template-columns: 1.5rem minmax(0, 1fr); }
  .sources .read { grid-column: 2; text-align: left; }
  .prose th, .prose td { min-width: 8rem; }
}

/* ---------- Wide: stub column beside the reading column ---------- */
@media (min-width: 64rem) {
  .piece {
    display: grid;
    grid-template-columns: var(--stub) minmax(0, var(--measure)) minmax(0, 1fr);
    column-gap: var(--gap);
    align-items: start;
  }
  .piece > * { grid-column: 2; }
  .piece > h1 { grid-column: 2 / 4; grid-row: 1; }
  .piece > .standfirst { grid-row: 2; }
  .piece > .stub { grid-column: 1; }
  .piece > .dateline { grid-row: 2; flex-direction: column; margin-top: 0; padding-top: 0.3rem; }
  .piece > .contents { grid-row: 3; position: sticky; top: var(--s4); margin: var(--s5) 0 0; padding: 0; background: none; }
  .piece > .prose { grid-row: 3; grid-column: 2 / 4; }
  .piece.plain > .dateline { grid-row: 2; padding-top: calc(var(--s4) + 0.3rem); }
  .piece.plain > .prose { grid-row: 2; margin-top: var(--s4); }
  .piece.plain > h1 { margin-bottom: 0; }
  .route { margin-left: calc(-1 * var(--s4) - var(--line)); padding-left: var(--s4); }
  .route h2::before { left: calc(-1 * var(--s4) - var(--line) / 2 - var(--stop) / 2); }
  .prose table { max-width: min(100%, 58rem); }
  .piece > .questions, .piece > .sources { max-width: none; }
  .contents ol { padding-left: 1.5rem; }

  .listing { display: grid; grid-template-columns: var(--stub) minmax(0, 1fr); column-gap: var(--gap); }
  .listing > * { grid-column: 2; }
  .listing > .index, .river > .index, .more > .index { grid-column: 1 / -1; }
  .index > li {
    grid-template-columns: var(--stub) minmax(0, var(--measure)) minmax(0, 1fr);
    grid-template-areas: "date entry topic";
    column-gap: var(--gap);
    align-items: baseline;
    margin-inline: calc(-1 * var(--s3));
  }
  .index > li > .topic { text-align: left; }
  .lead-story, .river > h2, .river > .all { padding-left: calc(var(--stub) + var(--gap)); }
  .river > h2, .river > .all { padding-left: calc(var(--stub) + var(--gap)); }
  .more { grid-column: 1 / 4; }
  .more > h2 { padding-left: calc(var(--stub) + var(--gap)); }
  .front-inner { padding-left: calc(var(--stub) + var(--gap)); }
  .colophon-inner { grid-template-columns: var(--stub) minmax(0, 1fr); }
  .colophon-name { grid-row: 1 / 4; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto; } }
@media print {
  .band, .colophon, .more, .contents { display: none; }
  html, body, .sources, .prose th { background: #fff; }
  .route { border-left-color: #000; }
}
