/* The pages of the Glint specification, set as a book: Crimson Text for the
   text and the headings, IBM Plex Mono for the computer's voice (bytes,
   offsets, code, field and record names), Inter for the dense cells of the
   tables. Ink on paper, and no interface chrome. */

@font-face {
  font-family: "Crimson Text";
  src: url("/fonts/crimson-text-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Crimson Text";
  src: url("/fonts/crimson-text-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Crimson Text";
  src: url("/fonts/crimson-text-semibold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Crimson Text";
  src: url("/fonts/crimson-text-semibolditalic.woff2") format("woff2");
  font-weight: 600;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono-bold.woff2") format("woff2");
  font-weight: 600 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("/fonts/inter.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --font-text: "Crimson Text", Garamond, "Iowan Old Style", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --font-table: "Inter", system-ui, sans-serif;

  --paper: oklch(0.99 0.002 90);
  --ink: oklch(0.24 0.008 70);
  --ink-soft: oklch(0.47 0.01 70);
  --rule: oklch(0.24 0.008 70 / 0.55);
  --hairline: oklch(0.24 0.008 70 / 0.18);
  --link: oklch(0.36 0.07 255);
  --selection: oklch(0.9 0.02 90);
  --code-ink: oklch(0.38 0.06 200);
  --code-ground: oklch(0.24 0.008 70 / 0.055);

  --measure: 33em;

  /* The type scale. The body size sets every paragraph, list and h3-h6
     heading; --small sets every secondary line (running head, contents,
     document facts, pager, foot); h1 and h2 are the only larger sizes.
     Inter in tables and IBM Plex Mono are sized to the x-height of the
     text. Do not add another size. */
  --size-body: 1.375rem;
  --size-h2: 1.1em;
  --size-h1: 1.75em;
  --size-mono: 0.7em;
  --size-nav: 0.72em;
  --size-table: 0.72em;
  --rail: 13rem;
  --rail-gap: clamp(2.5rem, 5vw, 5rem);
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --paper: oklch(0.2 0.006 70);
    --ink: oklch(0.88 0.008 85);
    --ink-soft: oklch(0.7 0.01 85);
    --rule: oklch(0.88 0.008 85 / 0.5);
    --hairline: oklch(0.88 0.008 85 / 0.16);
    --link: oklch(0.82 0.05 250);
    --selection: oklch(0.36 0.02 85);
    --code-ink: oklch(0.82 0.06 190);
    --code-ground: oklch(0.88 0.008 85 / 0.08);
  }
}

/* The switch of a review build sets the scheme on the root element. */
:root[data-scheme="dark"] {
  color-scheme: dark;
  --paper: oklch(0.2 0.006 70);
  --ink: oklch(0.88 0.008 85);
  --ink-soft: oklch(0.7 0.01 85);
  --rule: oklch(0.88 0.008 85 / 0.5);
  --hairline: oklch(0.88 0.008 85 / 0.16);
  --link: oklch(0.82 0.05 250);
  --selection: oklch(0.36 0.02 85);
  --code-ink: oklch(0.82 0.06 190);
  --code-ground: oklch(0.88 0.008 85 / 0.08);
}

:root[data-scheme="light"] {
  color-scheme: light;
}

.scheme-switch {
  margin-left: 1.5em;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
}

.scheme-switch:hover {
  color: var(--ink);
}

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--hairline) var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--size-body);
  line-height: 1.4;
  font-kerning: normal;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  hanging-punctuation: first allow-end;
  caret-color: var(--ink);
}

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

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-color: color-mix(in oklch, var(--link) 35%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

a:hover {
  text-decoration-color: var(--link);
}

code,
pre {
  font-family: var(--font-mono);
  font-size: var(--size-mono);
  hyphens: manual;
  font-variant-numeric: tabular-nums;
  hanging-punctuation: none;
}

/* The computer's voice is an insert in the text: its own ink, a faint
   ground and a size whose x-height matches the serif's. */
code {
  color: var(--code-ink);
}

p code,
li code,
h2 code,
h3 code,
h4 code,
dd code {
  padding: 0.08em 0.28em;
  border-radius: 0.2em;
  background: var(--code-ground);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

pre {
  margin: 0 0 1em;
  padding: 0.75em 1em;
  overflow-x: auto;
  line-height: 1.45;
  background: var(--code-ground);
  color: var(--code-ink);
}

pre code {
  font-size: 1em;
}

.skip {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  color: var(--ink);
}

.skip:focus {
  top: 0.75rem;
}

/* The running head: the name of the specification and its documents, as
   one line of text. */

.sheet-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 2rem;
  max-width: 100rem;
  margin: 0 auto;
  padding: 1.75rem var(--gutter) 0;
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.sheet-id {
  margin: 0;
}

.mark {
  color: var(--ink);
  text-decoration: none;
}

.mark:hover {
  text-decoration: underline;
  text-decoration-color: var(--rule);
}

.sheet-path {
  display: none;
}

.documents {
  margin-left: auto;
}

.documents ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.documents a {
  color: var(--ink-soft);
  text-decoration: none;
}

.documents a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--rule);
}

.documents a[aria-current="page"] {
  color: var(--ink);
  font-weight: 500;
}

/* The page: the contents in the left margin, then the text. */

.sheet {
  max-width: 100rem;
  margin: 0 auto;
  padding: 3.5rem var(--gutter) 0;
}

main {
  min-width: 0;
}

.rail {
  display: none;
}

@media (min-width: 70rem) {
  .sheet.has-rail {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
    column-gap: var(--rail-gap);
  }

  .rail {
    display: block;
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
    padding: 0.5rem 0.5rem 2rem 0;
    font-family: var(--font-table);
    font-size: var(--size-nav);
    line-height: 1.45;
    line-height: 1.4;
    scrollbar-width: thin;
  }

  .contents-inline {
    display: none;
  }
}

.rail-label {
  margin: 0 0 0.75rem;
  font-weight: 500;
}

.rail-label a {
  color: var(--ink);
  text-decoration: none;
}

.rail ol,
.contents-inline ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail li,
.contents-inline li {
  margin: 0;
  hyphens: manual;
}

.rail a,
.contents-inline nav a {
  display: block;
  padding: 0.1875rem 0 0.1875rem 1em;
  text-indent: -1em;
  color: var(--ink);
  text-decoration: none;
}

.rail a:hover,
.contents-inline nav a:hover {
  text-decoration: underline;
  text-decoration-color: var(--rule);
}

.rail li ol,
.contents-inline li ol {
  margin: 0 0 0.5rem 1em;
}

.rail li ol a,
.contents-inline li ol a {
  padding: 0.125rem 0 0.125rem 1em;
  color: var(--ink-soft);
}

.rail code,
.contents-inline code {
  font-size: 1em;
}

.contents-inline {
  max-width: var(--measure);
  margin: 0 0 2.5rem;
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.contents-inline summary {
  color: var(--link);
  font-weight: 500;
  list-style: none;
  cursor: pointer;
}

.contents-inline summary::-webkit-details-marker {
  display: none;
}

.contents-inline nav {
  padding: 0.75rem 0 0;
}

/* The title and the facts of the document, as a line of text. */

.title-block {
  max-width: var(--measure);
  margin: 0 0 3rem;
}

.title-block h1 {
  margin: 0 0 0.75rem;
  font-size: var(--size-h1);
  font-weight: 400;
  line-height: 1.1;
  text-wrap: balance;
}

.title-block dl {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--font-table);
  font-size: var(--size-nav);
  line-height: 1.6;
  font-variant-numeric: oldstyle-nums;
}

.title-block dl > div,
.title-block dt,
.title-block dd {
  display: inline;
}

.title-block dt {
  font-weight: 500;
}

@media (min-width: 40rem) {
  .title-block dl > div {
    white-space: nowrap;
  }
}

.title-block dd {
  margin: 0 1.5em 0 0.4em;
}

/* The text. Each block keeps the measure; a table may take the full
   width. */

.prose {
  max-width: 62em;
  font-variant-numeric: oldstyle-nums proportional-nums;
}

.prose > * {
  max-width: var(--measure);
}

.prose > .table-scroll,
.prose > .record,
.prose > pre {
  max-width: 100%;
}

.prose > :first-child {
  margin-top: 0;
}

p,
ul,
ol {
  margin: 0 0 0.9em;
}

p,
li {
  text-wrap: pretty;
  hyphens: auto;
}

ul,
ol {
  padding-left: 1.25em;
}

li {
  margin: 0.2em 0;
}

li > ul,
li > ol {
  margin: 0.2em 0 0.4em;
}

li::marker {
  color: var(--ink-soft);
}

h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: 600;
  line-height: 1.25;
  text-wrap: balance;
  scroll-margin-top: 1.5rem;
}

/* Section headings, after Practical Typography ("Headings"): emphasis
   comes from space, the same above and below at every level, and from the
   smallest visible step in size. No capitals, no underline, no centring. */
h2,
h3,
h4,
h5,
h6 {
  margin: 2em 0 0.5em;
  hyphens: manual;
  break-after: avoid;
}

h2 {
  font-size: var(--size-h2);
}

h3 {
  font-size: 1em;
}

h4,
h5,
h6 {
  font-size: 1em;
  font-style: italic;
  font-weight: 400;
}

a.anchor {
  color: inherit;
  text-decoration: none;
}

/* A heading is never underlined (Practical Typography, "Underlining"): the
   heading that a link or the pointer selects takes the link colour. */
a.anchor:hover,
:target > a.anchor {
  color: var(--link);
}

strong {
  font-weight: 600;
}

.unpublished {
  text-decoration: underline dotted var(--rule);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

/* Tables: a rule above, a rule under the column names and a rule below;
   no boxes. Numbers align on the right in the monospace. */

.table-scroll {
  margin: 0.4em 0 1.6em;
  overflow-x: auto;
  scrollbar-width: thin;
}

table {
  border-collapse: collapse;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-table);
  font-size: var(--size-table);
  line-height: 1.5;
  font-variant-numeric: lining-nums tabular-nums;
}

/* Inside the tables the sans sets the meaning; code keeps the mono at the
   table's size. */
table code {
  font-size: 1em;
}

th,
td {
  padding: 0.35em 1.25em 0.35em 0;
  text-align: left;
  vertical-align: baseline;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

thead th {
  padding-top: 0.45em;
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--hairline);
  font-weight: 400;
  white-space: nowrap;
}

tbody tr:first-child td {
  padding-top: 0.55em;
}

tbody tr:last-child td {
  padding-bottom: 0.55em;
}

th.num,
td.num {
  text-align: right;
}

td.num,
td.type {
  font-family: var(--font-mono);
  font-size: 1em;
}

td.num {
  white-space: nowrap;
}

.layout td.type,
.layout td.field {
  white-space: nowrap;
}

td.meaning {
  min-width: 20em;
  max-width: var(--measure);
}

td.nowrap {
  white-space: nowrap;
}

td.field code {
  font-size: 1em;
}

/* A record table: its name and its size as a caption. */

.record {
  display: grid;
  width: fit-content;
  max-width: 100%;
  margin: 1.2em 0 1.8em;
  scroll-margin-top: 1.5rem;
}

.record .table-scroll {
  margin: 0;
}

.record figcaption {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  margin-bottom: 0.35em;
}

.record-name {
  color: var(--ink);
  text-decoration: none;
}

.record-name code {
  font-weight: 400;
}

.record-name:hover,
.record:target .record-name {
  text-decoration: underline;
  text-decoration-color: var(--rule);
}

.dimension-value {
  color: var(--ink-soft);
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

/* The way forward and the foot of the page, as text. */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 2rem;
  max-width: var(--measure);
  margin: 4em 0 0;
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.pager a {
  color: var(--ink);
  text-decoration: none;
}

.pager a:hover {
  text-decoration: underline;
  text-decoration-color: var(--rule);
}

.pager a[rel="next"] {
  grid-column: 2;
  text-align: right;
}

.pager span {
  display: block;
  color: var(--ink-soft);
}

.sheet-foot {
  max-width: 100rem;
  margin: 5rem auto 0;
  padding: 0 var(--gutter) 3rem;
  color: var(--ink-soft);
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.sheet-foot p {
  max-width: 38rem;
  margin: 0 0 0.25rem;
}

@media (min-width: 70rem) {
  .sheet.has-rail + .sheet-foot {
    padding-left: calc(var(--gutter) + var(--rail) + var(--rail-gap));
  }
}

@media (max-width: 40rem) {
  body {
    font-size: 1.1875rem;
  }

  .sheet {
    padding-top: 2.5rem;
  }

  .title-block h1 {
    font-size: 1.5em;
  }

  td.meaning {
    min-width: 16em;
  }
}

@media print {
  .rail,
  .contents-inline,
  .pager,
  .skip {
    display: none;
  }

  .sheet.has-rail {
    display: block;
  }

  .table-scroll {
    overflow: visible;
  }
}

/* The line diff of a changed section on a draft's changes page: a line of
   the earlier draft in the soft ink, a line of this draft in the code ink. */
.diff-removed {
  color: var(--ink-soft);
}

.diff-added {
  color: var(--code-ink);
}

/* The decoder: the messages of a file, the selected message and the
   records of a stream of its frame. Functional text, in the sans. */
.decoder-status {
  font-family: var(--font-table);
  font-size: var(--size-nav);
  color: var(--ink-soft);
}

.decoder-status[role="alert"] {
  color: var(--ink);
}

.decoder-messages tr[aria-current] td {
  background: var(--code-ground);
}

.decoder-detail pre code {
  white-space: pre-wrap;
  word-break: break-word;
}

.decoder-streams ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0 0 1em;
  padding: 0;
  list-style: none;
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.decoder-streams a[aria-current="page"] {
  color: var(--ink);
  font-weight: 500;
  text-decoration: none;
}

.decoder-records td code {
  white-space: normal;
  word-break: break-word;
}

.decoder input[type="file"] {
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

.prose > .decoder {
  max-width: 100%;
}

.decoder-chooser {
  font-family: var(--font-table);
  font-size: var(--size-nav);
}

/* On a wide window the messages and the selected message sit side by
   side; the list scrolls on its own. */
@media (min-width: 70rem) {
  .decoder-view {
    display: grid;
    grid-template-columns: minmax(20rem, max-content) minmax(0, 1fr);
    column-gap: 2.5rem;
    align-items: start;
  }

  .decoder-view > .table-scroll {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }

  .decoder-detail h2 {
    margin-top: 0;
  }
}

.decoder-records td:nth-child(2) {
  white-space: nowrap;
}

/* The landing page's clip: the canvas at the width of the text column,
   at the clip's aspect ratio. */
.landing-clip {
  margin: 1.5em 0;
}

.landing-clip canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--code-ground);
}

.landing-clip figcaption {
  margin-top: 0.6em;
  color: var(--ink-soft);
  font-family: var(--font-table);
  font-size: var(--size-nav);
}
