/* Rowan Chell. After Low-tech Magazine: system serif, ink on paper, hairline rules, no boxes. */

:root {
  --ink: #000000;
  --muted: #666666;        /* darker than the original #828282 so small text passes WCAG AA */
  --paper: #F0F8FF;
  --blue: #3353FF;
  --red: #E01300;
  --green: #20795E;
  --gap: 20px;
  /* Pictures always print on light paper in their original inks, in both themes. */
  --img-paper: #F0F8FF;
  --img-ink: #000000;
  --img-blue: #162DAB;
  --img-red: #D11305;
  --img-green: #006951;
  --img-grey: #666666;     /* design pictures on hover */
  color-scheme: light;
}

/* Dark: chosen with the toggle, or the system setting when nothing is chosen. */
:root[data-theme="dark"] {
  --ink: #E6EBF2;
  --muted: #A3ACB8;
  --paper: #12161D;
  --blue: #93A4FF;
  --red: #FF7F73;
  --green: #52D1AA;
  --img-paper: #DCE3EC;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E6EBF2;
    --muted: #A3ACB8;
    --paper: #12161D;
    --blue: #93A4FF;
    --red: #FF7F73;
    --green: #52D1AA;
    --img-paper: #DCE3EC;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { background: var(--paper); overflow-x: hidden; overflow-x: clip; scroll-padding-top: 20px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  padding: 0 var(--gap);
  background: var(--paper);
  color: var(--ink);
  font-family: "Times New Roman", Tinos, "Liberation Serif", Times, serif;
  font-size: 20px;
  font-weight: 400;
  line-height: normal;
  overflow-x: hidden;
  overflow-x: clip;  /* clip, not hidden, so body is not a scroll box and sticky works */
  overflow-wrap: break-word;
  /* keep the footer at the bottom of the window when a page is short */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
main { flex: 1 0 auto; }
footer { flex-shrink: 0; }

img, canvas { max-width: 100%; }
h1, h2, h3 { font-weight: 400; margin: 0; }
p { margin: 0; }

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--muted); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.ul { padding-bottom: 1px; border-bottom: 1px solid var(--ink); }
.ul:hover { border-color: var(--muted); }

.meta { font-family: monospace; font-size: 14px; line-height: 1.5; color: var(--muted); overflow-wrap: anywhere; }
.meta a { color: var(--muted); padding-bottom: 0.7px; border-bottom: 1px solid var(--muted); }
.meta a:hover { color: var(--ink); border-color: var(--ink); }

.skip {
  position: absolute;
  left: var(--gap);
  top: -100px;
  padding: 6px 10px;
  background: var(--ink);
  color: var(--paper);
  z-index: 10;
}
.skip:focus { top: 8px; color: var(--paper); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- header ---------- */
.site-header { padding: 10px 0; }
.logo { font-size: 50px; line-height: 50px; text-transform: uppercase; }
.logo a { color: var(--ink); }
.logo a:hover { color: var(--muted); }
.strap { line-height: 24px; }
.site-header nav { line-height: 30px; }
.site-header ul { list-style: none; margin: 0; padding: 0; }
.site-header li { display: inline-block; margin-right: 10px; }
.site-header .b { color: var(--blue); }
.site-header .r { color: var(--red); }
.site-header .g { color: var(--green); }
.site-header a:hover { color: var(--muted); }
.site-header a[aria-current="page"] { border-bottom: 1px solid currentColor; }
/* light/dark switch: in the footer, opposite the name */
.theme-toggle {
  flex-shrink: 0;
  font-family: monospace;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--muted);
  border-radius: 0;
  padding: 0 0 1px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink); }

/* ---------- intro ---------- */
.intro { max-width: 1040px; padding: 30px 0 10px; }
.intro p { font-size: 30px; line-height: 36px; }
.intro .ul { padding-bottom: 1.5px; }
.tags { display: flex; flex-wrap: wrap; margin: 14px 0 0; }
.tags > div { margin: 0 20px 5px 0; }

/* ---------- section mastheads ---------- */
.masthead { padding: 10px 0; margin-top: 60px; max-width: 1040px; }
.intro + .masthead, .masthead.first, .masthead.first + .masthead { margin-top: 20px; }
.masthead h1, .masthead h2 { font-size: 50px; line-height: 50px; margin: 20px 0 10px; }
.masthead p { font-size: 30px; line-height: 36px; }
.masthead.blue :is(h1, h2) { color: var(--blue); }
.masthead.red :is(h1, h2) { color: var(--red); }
.masthead.green :is(h1, h2) { color: var(--green); }

/* ---------- 1-bit image with colour overlay ---------- */
.dither {
  position: relative;
  width: 100%;
  aspect-ratio: 480 / 314;
  margin: 10px 0;
  background: var(--img-paper);
  isolation: isolate;
  overflow: hidden;
}
.dither img { display: block; width: 100%; height: 100%; object-fit: contain; }
.dither::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tint);
  mix-blend-mode: screen;
  pointer-events: none;
}
.t-blue { --tint: var(--img-blue); }
.t-red { --tint: var(--img-red); }
.card:hover .dither::after, .card a:focus-visible .dither::after { background: var(--img-grey); }

/* ---------- design cards ---------- */
.index {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}
.card a { display: block; }
.card a:hover { color: var(--ink); }
.card h3 { font-size: 23.4px; line-height: 1.5; margin: 20px 0 10px; }
.card h3 span { padding-bottom: 1px; border-bottom: 1px solid var(--ink); }
.card a:hover h3 span { color: var(--muted); border-color: var(--muted); }
.card p { line-height: 28px; }
.card .meta { display: block; margin-top: 5px; }

/* ---------- project list ---------- */
.list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 30px var(--gap);
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}
.list li { border-top: 1px solid var(--ink); padding-top: 10px; }
.list h3 { font-size: 23.4px; line-height: 1.3; margin-bottom: 8px; }
.list h3 a { padding-bottom: 1px; border-bottom: 1px solid var(--ink); }
.list h3 a:hover { border-color: var(--muted); }
.list p { line-height: 28px; }
.list .meta { display: block; margin-top: 5px; }
.more { margin-top: 30px; line-height: 28px; }

/* ---------- dither tool ---------- */
.tool {
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(0, 1fr);
  gap: 20px 40px;
  margin-top: 20px;
  align-items: start;
}
.stage { margin: 0; }
.canvas-wrap { position: relative; background: var(--img-paper); }
.canvas-wrap.drag { outline: 2px dashed var(--ink); outline-offset: 6px; }
#out { display: block; width: 100%; height: auto; image-rendering: pixelated; touch-action: none; cursor: grab; }
#out:active { cursor: grabbing; }
.stage figcaption { font-size: 16.8px; line-height: 1.5; margin-top: 10px; }
.stats { margin-top: 6px; }

.controls { border-bottom: 1px solid var(--ink); }
.row { border: 0; border-top: 1px solid var(--ink); margin: 0; padding: 10px 0; min-width: 0; }
.row::after { content: ""; display: block; clear: both; }
.row-label {
  float: left;
  width: 8.5rem;
  padding: 4px 0 0;
  font-family: monospace;
  font-size: 14px;
  color: var(--muted);
}
.row-body { margin-left: 9rem; line-height: 30px; }
.choice { display: inline-block; margin-right: 14px; cursor: pointer; white-space: nowrap; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice span { color: var(--muted); padding-bottom: 1px; border-bottom: 1px solid transparent; }
.choice:hover span { color: var(--ink); }
.choice input:checked + span { color: var(--ink); border-color: var(--ink); }
.choice input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }
.choice.c-blue input:checked + span { color: var(--blue); border-color: var(--blue); }
.choice.c-red input:checked + span { color: var(--red); border-color: var(--red); }
.choice.c-green input:checked + span { color: var(--green); border-color: var(--green); }
.file { cursor: pointer; }
.file input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file span { padding-bottom: 1px; border-bottom: 1px solid var(--ink); }
.file:hover span { color: var(--muted); border-color: var(--muted); }
.file input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 3px; }

/* thin ruled sliders with a square thumb */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;
  margin: 0;
  background: transparent;
  vertical-align: middle;
}
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; margin-top: -6.5px;
  background: var(--ink); border: 0; border-radius: 0;
}
input[type=range]::-moz-range-track { height: 1px; background: var(--ink); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; background: var(--ink); border: 0; border-radius: 0; }
input[type=range]:focus-visible { outline-offset: 0; }

.btn {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  padding: 0 0 1px;
  margin-right: 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.btn:hover { color: var(--muted); border-color: var(--muted); }

/* ---------- about ---------- */
.about {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  margin-top: 20px;
}
.about figure { margin: 0; }
.about figure .dither { margin-top: 0; }
.about figcaption { font-size: 16.8px; line-height: 1.5; }
.about .body { grid-column: 2 / 4; }
.about .body p { line-height: 1.45; margin-bottom: 1em; }
.facts { margin: 0; border-bottom: 1px solid var(--ink); }
.facts div { border-top: 1px solid var(--ink); padding: 6px 0 7px; }
.facts dt { font-family: monospace; font-size: 14px; color: var(--muted); }
.facts dd { margin: 0; line-height: 1.35; }

/* ---------- footer ---------- */
footer { border-top: 2px solid var(--ink); margin-top: 80px; padding: 10px 0 44px; }  /* room for the fixed readout */
.footer-top { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; flex-wrap: wrap; }
footer h2 { font-size: 30px; text-transform: uppercase; }
.cols {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--gap);
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
}
.cols h3 { font-size: 23.4px; margin-bottom: 4px; }
.cols p { line-height: 28px; }
/* a footer link list runs down 4 rows, then starts another column */
.cols .stack { display: grid; grid-template-rows: repeat(4, auto); grid-auto-flow: column; justify-content: start; column-gap: var(--gap); }
.readout { font-family: monospace; font-size: 14px; line-height: 1.6; }
.readout span { color: var(--muted); display: inline-block; min-width: 9ch; }
.readout b { font-weight: 400; color: var(--ink); }
.colophon { margin-top: 40px; padding: 10px 0 0; border-top: 1px solid var(--ink); display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* fixed readout bottom-left; back-to-top sticks bottom-right until it meets the footer */
.status { position: fixed; left: calc(var(--gap) - 4px); bottom: 0; padding: 3px 4px 5px; font-family: monospace; font-size: 14px; background: var(--paper); color: var(--ink); }
.status span + span { margin-left: 14px; }
.to-top-wrap {
  position: sticky;
  bottom: 10px;
  align-self: flex-end;
  height: 0;
  margin-top: 70px;  /* splits the footer's 80px top margin: rest 10px above its rule */
  z-index: 5;
}
.to-top-wrap + footer { margin-top: 10px; }
.to-top {
  position: absolute;
  right: 0;
  bottom: 0;
  white-space: nowrap;
  padding: 6px 10px;
  font-family: monospace;
  font-size: 14px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  visibility: hidden;
  opacity: 0;
}
.to-top.show { visibility: visible; opacity: 1; }
.to-top:hover { color: var(--paper); background: var(--ink); }

/* ---------- plain text pages (privacy, 404) ---------- */
.prose { max-width: 680px; margin-top: 10px; }
.prose h2 { font-size: 30px; line-height: 1.3; margin: 34px 0 8px; }
.prose p, .prose li { line-height: 1.45; }
.prose p + p { margin-top: 0.9em; }
.prose ul { padding-left: 1.1em; margin: 0.6em 0 0; }
.prose li + li { margin-top: 0.4em; }

/* ---------- tablet ---------- */
@media (max-width: 1000px) {
  .index, .list, .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .about { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .about .body { grid-column: 1 / -1; grid-row: 2; }
  .tool { grid-template-columns: minmax(0, 1fr); }
  .stage { max-width: 480px; }
}

/* the fixed readout sits over body text on tablets and touch screens, where nothing moves it aside */
@media (max-width: 1000px), (hover: none) {
  .status { display: none; }
  footer { padding-bottom: 24px; }
}

/* ---------- touch: bigger invisible hit areas on small links and controls ---------- */
@media (pointer: coarse) {
  .site-header a, .list h3 a, .cols .ul, .links .ul, .meta a, .theme-toggle, .btn, .choice span, .file span {
    position: relative;
    white-space: nowrap;  /* one box per link, so the hit area can't spread across a paragraph */
  }
  .site-header a::after, .list h3 a::after, .cols .ul::after, .links .ul::after, .meta a::after, .theme-toggle::after,
  .btn::after, .choice span::after, .file span::after, .to-top::after {
    content: "";
    position: absolute;
    inset: calc(-1 * var(--hit-y, 8px)) -6px;
  }
  .site-header a { --hit-y: 8px; }
  .meta a { --hit-y: 6px; }
  .choice span { --hit-y: 7px; }
  .to-top { padding: 10px 14px; }
  .tags > div { margin-bottom: 12px; }
  .cols .ul { --hit-y: 1px; }  /* stacked footer links keep their spacing, so their hit areas can't grow into each other */
  .links li + li { margin-top: 14px; }
  input[type=range] { height: 44px; }
}

/* ---------- phone ---------- */
@media (max-width: 600px) {
  body { font-size: 16px; padding: 0 16px; }
  .site-header { padding: 8px 0; }
  .logo { font-size: 32px; line-height: 32px; }
  .strap { line-height: 19.2px; }
  .site-header nav { line-height: 32px; margin-top: 2px; }
  .site-header ul { display: flex; flex-wrap: wrap; column-gap: 15px; }  /* no inline-block whitespace: fits one line at 320px */
  .site-header li { margin-right: 0; }
  .intro { padding-top: 20px; }
  .intro p, .masthead p { font-size: 22px; line-height: 28px; }
  .masthead { margin-top: 44px; }
  .masthead h1, .masthead h2 { font-size: 36px; line-height: 38px; }
  .index, .list { grid-template-columns: minmax(0, 1fr); }
  .card h3, .list h3 { font-size: 20px; }
  .card p, .list p { line-height: 1.4; }
  .about { grid-template-columns: minmax(0, 1fr); }
  .about .body { grid-row: auto; }
  .row-label { width: 100%; padding: 0 0 2px; }
  .row-body { clear: both; margin-left: 0; line-height: 34px; }
  .cols { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .cols h3 { font-size: 18.72px; }
  .cols p { line-height: 22.4px; }
  footer h2 { font-size: 24px; }
  .prose h2 { font-size: 24px; }
}

/* ---------- print: ink on white paper, without the parts you can't click ---------- */
@media print {
  :root, :root[data-theme="dark"], :root:not([data-theme="light"]) {
    --ink: #000000; --muted: #444444; --paper: #FFFFFF;
    --blue: #162DAB; --red: #D11305; --green: #006951;
    --img-paper: #FFFFFF;
    color-scheme: light;
  }
  .skip, .site-header nav, .to-top-wrap, .status, .theme-toggle, footer .cols,
  form.controls, #request, #change, .cal, .cal + .meta { display: none !important; }
  footer { margin-top: 30px; padding-bottom: 0; }
  .masthead { margin-top: 30px; }
  /* Paper can't follow a link, so show where each one outside the site goes. */
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-family: monospace; font-size: 12px; overflow-wrap: anywhere; }
  h1, h2, h3 { break-after: avoid; }
  figure, .list li, .card, .bins li { break-inside: avoid; }
}
