/* Prose & Pigment. Reading pages in the app's own faces and the Fresco pigments. */

@font-face {
  font-family: "Source Serif 4";
  src: url("/fonts/source-serif-4.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  src: url("/fonts/source-serif-4-italic.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  font-weight: 600;
  src: url("/fonts/source-serif-4-600.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #F5F1E6;
  --ink: #26221B;
  --quiet: #6C675D;
  --rule: #DAD4C5;
  /* Vermilion, darkened until it reads at 4.5:1 on paper. The Pigment theme's text value. */
  --lead: #B93C27;
  --code-ground: #EDE8DA;

  --text: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --code: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --margin: clamp(1.25rem, 5vw, 3rem);

  /* Shared pieces, each used in three or more places. */
  --small: 0.9375rem;
  --hairline: 1px solid var(--rule);
  --focus-ring: 2px solid var(--lead);
  --control-ease: 160ms ease-out;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #231A11;
    --ink: #ECE7DA;
    --quiet: #8F887C;
    --rule: #3A362F;
    --lead: #DA6653;
    --code-ground: #2A1F15;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.125rem;
  line-height: 1.45;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  font-synthesis: none;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--ink);
  color: var(--paper);
}

.page {
  max-width: 38rem;
  margin-inline: auto;
  padding: clamp(1.75rem, 6vw, 3.5rem) var(--margin) 3rem;
}

/* The masthead: the mark and the name, linking home. */

.masthead {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: clamp(2.5rem, 8vw, 4.5rem);
  padding-block: 0.4rem;
  color: var(--ink);
  font-weight: 600;
  font-size: 1.0625rem;
  text-decoration: none;
}
.masthead svg,
.masthead img {
  width: 2rem;
  height: 2rem;
  border-radius: 0.45rem;
}

h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}
h1 {
  font-size: clamp(1.875rem, 1.2rem + 3.4vw, 2.75rem);
  margin: 0 0 1rem;
}
h2 {
  font-size: 1.4375rem;
  margin: 2.75rem 0 0.6rem;
  padding-top: 1rem;
  border-top: 2px solid var(--lead);
}
h3 {
  font-size: 1.125rem;
  margin: 1.5rem 0 0.3rem;
}

p,
ul,
ol {
  margin: 0 0 1rem;
  text-wrap: pretty;
}
ul,
ol {
  padding-left: 1.3rem;
}
li {
  margin-bottom: 0.35rem;
}
li::marker {
  color: var(--lead);
}

.lede {
  font-size: clamp(1.1875rem, 1rem + 0.8vw, 1.3125rem);
  line-height: 1.38;
}
.quiet {
  color: var(--quiet);
}
.status {
  font-style: italic;
  color: var(--quiet);
}

a {
  color: var(--lead);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.17em;
  touch-action: manipulation;
}
a:hover,
a:active {
  text-decoration-thickness: 2px;
}
a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 2px;
}

code,
pre {
  /* Show the characters that are in the file, not joined-up arrows. */
  font-variant-ligatures: none;
}
code {
  font-family: var(--code);
  font-size: 0.86em;
  background: var(--code-ground);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

/* A list of links that each need a full-size touch target. */
.links {
  list-style: none;
  padding: 0;
  margin: 2rem 0 0;
}
.links li {
  margin: 0;
  border-top: var(--hairline);
}
.links li:last-child {
  border-bottom: var(--hairline);
}
.links a {
  display: block;
  padding-block: 0.8rem;
}

.small-print {
  margin-top: 3.5rem;
  padding-top: 1rem;
  border-top: var(--hairline);
  font-size: var(--small);
  color: var(--quiet);
}
.small-print a {
  color: inherit;
  /* A 44px target for links that sit alone in the footer. */
  display: inline-block;
  padding-block: 0.75rem;
  margin-block: -0.45rem;
  padding-inline: 0.25rem;
  margin-inline: -0.25rem;
}
.small-print p {
  margin-bottom: 0.3rem;
}

@media (prefers-contrast: more) {
  :root {
    --quiet: var(--ink);
    --rule: var(--ink);
  }
}

@media print {
  :root {
    --paper: #fff;
    --ink: #000;
    --quiet: #333;
    --rule: #999;
    --lead: #000;
    --code-ground: #eee;
  }
}

/* The landing page. Two files, each shown typeset or raw, switched without script. */

:root {
  --sheet: #FBF8F0;
  --tok-keyword: var(--lead);
  --tok-function: #34446E;
  --tok-string: #586F49;
  --tok-number: #82601E;
  --tok-type: #5E4034;
  --tok-comment: var(--quiet);
}
@media (prefers-color-scheme: dark) {
  :root {
    --sheet: #211E1A;
    --tok-function: #7488BD;
    --tok-string: #73915F;
    --tok-number: #BC8A2C;
    --tok-type: #AD7D6A;
  }
}

.landing {
  max-width: 42rem;
  padding-top: clamp(1.25rem, 5vw, 3.5rem);
  /* The space between sections: the page's main unit of white space. */
  --section-gap: clamp(4.5rem, 12vw, 7.5rem);
  --col-gap: clamp(3rem, 5vw, 5.5rem);
}
.landing .masthead {
  margin-bottom: clamp(1.75rem, 8vw, 5.5rem);
}
.landing h1 {
  font-size: clamp(2.125rem, 1.2rem + 4.6vw, 3rem);
  line-height: 1.08;
  margin-bottom: 1.25rem;
}
.landing .lede {
  max-width: 34rem;
  margin-bottom: 0;
}

/* Each section opens with a vermilion rule and a wide margin above it. */
.row,
.refusals,
.close {
  margin-top: var(--section-gap);
  padding-top: 1.75rem;
  border-top: var(--hairline);
}
/* The one vermilion rule on the page marks its loudest statement. */
.refusals {
  border-top: 3px solid var(--lead);
}
/* Two sections in a row are a pair, and sit at half the gap. */
.row + .row {
  margin-top: calc(var(--section-gap) / 2);
}
.landing h2 {
  margin: 0 0 1.5rem;
  padding: 0;
  border: 0;
}
.row-body > :last-child,
.refusals > :last-child {
  margin-bottom: 0;
}
.landing .small-print {
  margin-top: var(--section-gap);
}

.demo {
  border: 0;
  padding: 0;
  margin: clamp(1.75rem, 7vw, 3.5rem) 0 0;
  min-width: 0;
}

/* Wide screens: the headline stands beside the document, and every section keeps the same
   two columns, so its heading sits under the headline and its text under the sheet. */
@media (min-width: 64rem) {
  .landing {
    max-width: 78rem;
  }
  .hero,
  .row,
  .refusals {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    column-gap: var(--col-gap);
    align-items: start;
  }
  .hero-copy {
    position: sticky;
    top: 3.5rem;
  }
  .landing h1 {
    font-size: clamp(3rem, 4.4vw, 4rem);
    line-height: 1.04;
    margin-bottom: 2rem;
  }
  .landing .lede {
    font-size: clamp(1.1875rem, 1.45vw, 1.3125rem);
  }
  .hero .demo {
    margin-top: 0;
  }
  .set pre,
  .raw pre {
    font-size: var(--small);
  }
  .landing .row h2 {
    margin: 0;
    font-size: 1.75rem;
  }
  .row > :not(h2) {
    grid-column: 2;
  }
  .refusal-lines {
    grid-column: 1 / -1;
  }
  .refusals > p:last-child {
    grid-column: 1 / -1;
    max-width: 34rem;
  }
}
.switch {
  display: flex;
  justify-content: center;
  margin-bottom: 0.6rem;
}
.switch-track {
  display: inline-flex;
  border: 1.5px solid var(--ink);
  border-radius: 0.7rem;
  overflow: hidden;
  font-weight: 600;
  font-size: 1rem;
}
.switch label {
  min-width: min(6.5rem, 36vw);
  padding: 0.7rem min(1.25rem, 4vw);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color var(--control-ease), color var(--control-ease);
}
#view-raw:checked ~ .switch label[for="view-raw"],
#view-set:checked ~ .switch label[for="view-set"] {
  background: var(--ink);
  color: var(--paper);
}
#view-raw:focus-visible ~ .switch label[for="view-raw"],
#view-set:focus-visible ~ .switch label[for="view-set"] {
  outline: var(--focus-ring);
  outline-offset: -5px;
}
/* On the selected option the ring sits on ink, so it takes the paper colour to stay visible. */
#view-raw:checked:focus-visible ~ .switch label[for="view-raw"],
#view-set:checked:focus-visible ~ .switch label[for="view-set"] {
  outline-color: var(--paper);
}
@media (hover: hover) {
  #view-raw:not(:checked) ~ .switch label[for="view-raw"]:hover,
  #view-set:not(:checked) ~ .switch label[for="view-set"]:hover {
    background: var(--code-ground);
  }
}

/* One visible line that says what the switch is for. */
.demo-hint {
  margin: 0 0 0.6rem;
  font-size: var(--small);
  color: var(--quiet);
  text-align: center;
}

/* The two files, as tabs on the sheet's top edge. The open tab carries the vermilion rule. */
.tabs {
  display: flex;
  position: relative;
  z-index: 1;
  margin-bottom: -1px;
}
.tabs label {
  position: relative;
  padding: 0.35rem min(1rem, 4vw) 0.4rem;
  border: 1px solid transparent;
  border-top: 3px solid transparent;
  border-bottom: 0;
  border-radius: 0.4rem 0.4rem 0 0;
  color: var(--quiet);
  /* File names are file content, so they take the code face. */
  font-family: var(--code);
  font-variant-ligatures: none;
  font-size: 0.875rem;
  line-height: 1.75;
  cursor: pointer;
  touch-action: manipulation;
  transition: color var(--control-ease);
}
/* The tab is drawn short; its touch target reaches up into the gap above it. */
.tabs label::before {
  content: "";
  position: absolute;
  inset: -0.6rem 0 0;
}
.tabs label:hover {
  color: var(--ink);
}
#file-prose:checked ~ .tabs label[for="file-prose"],
#file-pigment:checked ~ .tabs label[for="file-pigment"] {
  background: var(--sheet);
  border-color: var(--rule);
  border-top-color: var(--lead);
  color: var(--ink);
}
#file-prose:focus-visible ~ .tabs label[for="file-prose"],
#file-pigment:focus-visible ~ .tabs label[for="file-pigment"] {
  outline: var(--focus-ring);
  outline-offset: -6px;
}

/* All four views occupy the same cell, so the page does not jump when they swap. */
.sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  background: var(--sheet);
  border: var(--hairline);
  border-radius: 0 0.5rem 0.5rem 0.5rem;
}
.pane {
  grid-area: 1 / 1;
  min-width: 0;
  padding: clamp(1.25rem, 5vw, 3rem);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease-out, visibility 0s linear 180ms;
}
#view-set:checked ~ #file-prose:checked ~ .sheet .prose.set,
#view-raw:checked ~ #file-prose:checked ~ .sheet .prose.raw,
#view-set:checked ~ #file-pigment:checked ~ .sheet .pigment.set,
#view-raw:checked ~ #file-pigment:checked ~ .sheet .pigment.raw {
  opacity: 1;
  visibility: visible;
  transition: opacity 180ms ease-out;
}

/* Names each view when the stylesheet is missing and all four show at once. */
.pane-label {
  display: none;
}
@media (prefers-reduced-motion: reduce) {
  .pane,
  .switch label,
  .tabs label {
    transition: none !important;
  }
}
/* Forced colours drop backgrounds, so the chosen option is marked with the system highlight. */
@media (forced-colors: active) {
  #view-raw:checked ~ .switch label[for="view-raw"],
  #view-set:checked ~ .switch label[for="view-set"],
  #file-prose:checked ~ .tabs label[for="file-prose"],
  #file-pigment:checked ~ .tabs label[for="file-pigment"] {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}

.set h2 {
  border: 0;
  padding: 0;
  margin: 0 0 1rem;
  font-size: 1.5rem;
}
.set p,
.set blockquote,
.set td,
.set th {
  /* The page's own body size; the demo document quotes it. */
  font-size: 1.125rem;
}
.set p {
  margin-bottom: 1.25rem;
}
.set pre,
.raw pre {
  margin: 0 0 1.75rem;
  font-family: var(--code);
  font-size: 0.8125rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* Code keeps its lines and scrolls sideways, as code does; it never wraps mid-statement. */
.set pre {
  background: var(--code-ground);
  border-radius: 0.4rem;
  padding: 1.15rem min(1.25rem, 4vw);
  white-space: pre;
  overflow-x: auto;
  overflow-wrap: normal;
}
.set pre code,
.raw pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}
.raw pre {
  margin: 0;
  color: var(--ink);
}
.sheet pre:focus-visible,
.table-scroll:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
  border-radius: 2px;
}
.k { color: var(--tok-keyword); }
.f { color: var(--tok-function); }
.s { color: var(--tok-string); }
.n { color: var(--tok-number); }
.t { color: var(--tok-type); }
.c { color: var(--tok-comment); font-style: italic; }

.set blockquote {
  text-wrap: balance;
  margin: 0 0 1.75rem;
  padding: 0.15rem 0 0.15rem 1.1rem;
  border-left: 3px solid var(--lead);
  font-style: italic;
}
/* A wide table scrolls sideways, as it does in the app. */
.table-scroll {
  overflow-x: auto;
}
.set table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}
.set th {
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--ink);
  padding: 0.3rem 0.75rem 0.6rem 0;
}
.set td {
  text-wrap: balance;
  padding: 0.6rem 0.75rem 0.6rem 0;
  border-bottom: var(--hairline);
}
.set p code,
.set td code {
  color: var(--tok-function);
}
/* A value and its unit stay on one line. */
.set td code {
  white-space: nowrap;
}

.demo-note {
  margin: 1.1rem 0 0;
  font-size: var(--small);
  color: var(--quiet);
}

/* What it shows: a plain list, set as the Pigment theme sets one. */
.shows {
  margin: 0;
  padding-left: 1.35rem;
}
.shows li {
  margin: 0;
  padding-block: 0.7rem;
  border-bottom: var(--hairline);
}
.shows li:first-child {
  padding-top: 0;
}
.shows li:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}
/* Inline code on the page matches the theme: indigo on the code ground. */
.shows code {
  color: var(--tok-function);
}

/* What it doesn't do: the three refusals at the headline's size. */
.refusal-lines {
  margin-bottom: 1.25rem;
  font-weight: 600;
  font-size: clamp(2.125rem, 1.2rem + 4.6vw, 3rem);
  line-height: 1.12;
}
.refusal-lines span {
  display: block;
}

.signature {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 2rem;
  font-style: italic;
}
.signature svg {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.36rem;
  flex: none;
}

/* The page ends on the name and where the app stands. */
.close {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 1.75rem);
}
.close > div {
  min-width: 0;
}
.close-mark {
  flex: none;
  width: clamp(4.5rem, 18vw, 6rem);
  height: auto;
  aspect-ratio: 1;
  border-radius: 22%;
}
.close-name {
  margin: 0 0 0.5rem;
  font-weight: 600;
  font-size: 1.75rem;
  line-height: 1.2;
}
.close .status {
  margin: 0;
}

/* Hardening: what the page does when conditions are not the ones it was drawn for. */

/* Code and raw files read left to right whatever direction the page is in. */
pre {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}

.name {
  white-space: nowrap;
}

/* Read aloud and reachable by keyboard, never drawn: hidden labels, the demo's radio buttons
   and legend, and the refusals' heading. */
.vh,
.demo legend,
.demo input,
.landing .refusals h2 {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A translated label can be half again as long: the switch grows, then wraps, before it overflows. */
.switch-track {
  max-width: 100%;
  flex-wrap: wrap;
}
.switch label {
  flex: 1 1 auto;
}
.tabs {
  flex-wrap: wrap;
}
.tabs label {
  white-space: nowrap;
}

/* Text set very large, or a very narrow window: the column is under 18 of the reader's own
   ems. Long words hyphenate instead of snapping mid-letter, and the switch stacks. */
@media (max-width: 18em) {
  h1,
  .refusal-lines,
  .close-name {
    hyphens: auto;
    -webkit-hyphens: auto;
  }
  .switch-track {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  .switch label {
    min-width: 0;
  }
  .name {
    white-space: normal;
  }
  .close {
    flex-wrap: wrap;
  }
}

/* On paper: light pigments whatever the screen was showing, no controls, and each file
   printed once, typeset. */
@media print {
  p,
  li {
    orphans: 2;
    widows: 2;
  }
  h1,
  h2,
  h3 {
    break-after: avoid;
  }
  :root {
    color-scheme: light;
    --sheet: #fff;
    --tok-keyword: #9A2F1D;
    --tok-function: #2B3960;
    --tok-string: #45593A;
    --tok-number: #6B4E14;
    --tok-type: #4D332A;
    --tok-comment: #555;
  }
  .switch,
  .tabs,
  .demo .raw {
    display: none !important;
  }
  .demo .sheet {
    display: block !important;
    border-radius: 0;
  }
  /* These outrank the on-screen state rules, which are keyed to the controls' ids. */
  .demo .sheet .pane.set {
    opacity: 1 !important;
    visibility: visible !important;
    overflow: visible !important;
    clip-path: none !important;
    background: none !important;
    border-left: 0 !important;
    transition: none !important;
    break-inside: avoid;
  }
  .demo .sheet .pane.set > * {
    width: auto !important;
  }
  .demo .sheet .pane.pigment {
    border-top: var(--hairline);
  }
  .set pre {
    white-space: pre-wrap;
    overflow: visible;
  }
}
