/*
 * SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>
 * SPDX-License-Identifier: MIT
 */

/* A reference manual on warm paper: serif prose, a mono for anything that
 * is bytes, and the terminal itself as the one dark object on the page. */

:root {
  --paper: #f5f1e8;
  --paper-2: #ece6d8;
  --ink: #1e222b;
  --muted: #676a72;
  --rule: #d6cdb9;
  --accent: #b5442a;
  --link: #24577f;
  --ok: #2c7a4b;
  --ok-wash: #dcecdf;
  --bad: #b1261d;
  --bad-wash: #f4d9d4;
  --warn: #93600a;
  --warn-wash: #f3e5c4;
  --term-bg: #15181e;
  --term-fg: #e8e2d4;
  --term-dim: #545a66;
  --term-cursor: #f0a64a;

  --serif: "Charter", "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --mono: ui-monospace, "Adwaita Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #181a1f;
    --paper-2: #21242b;
    --ink: #e4dfd3;
    --muted: #9a9ca3;
    --rule: #353943;
    --accent: #ec8a64;
    --link: #8ec1ea;
    --ok: #7cc996;
    --ok-wash: #1d3326;
    --bad: #f08a80;
    --bad-wash: #3d2220;
    --warn: #e6b45c;
    --warn-wash: #3a2f19;
    --term-bg: #0d0f12;
    --term-fg: #e8e2d4;
    --term-dim: #4a505c;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #181a1f;
  --paper-2: #21242b;
  --ink: #e4dfd3;
  --muted: #9a9ca3;
  --rule: #353943;
  --accent: #ec8a64;
  --link: #8ec1ea;
  --ok: #7cc996;
  --ok-wash: #1d3326;
  --bad: #f08a80;
  --bad-wash: #3d2220;
  --warn: #e6b45c;
  --warn-wash: #3a2f19;
  --term-bg: #0d0f12;
  --term-fg: #e8e2d4;
  --term-dim: #4a505c;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.6 var(--serif);
}

a {
  color: var(--link);
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

code,
kbd,
pre {
  font-family: var(--mono);
  font-size: 0.86em;
}

:not(pre) > code {
  background: var(--paper-2);
  border-radius: 3px;
  padding: 0.05em 0.3em;
}

/* ---- frame ---------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font: 600 1.05rem/1 var(--mono);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.wordmark .esc {
  color: var(--accent);
  margin-right: 0.35em;
}

.engine {
  font: 0.8rem/1 var(--mono);
  color: var(--muted);
}

.frame {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  max-width: 78rem;
  margin: 0 auto;
}

.index {
  padding: 1.5rem 1.25rem 3rem 1.5rem;
  border-right: 1px solid var(--rule);
  font-size: 0.92rem;
}

.index section + section {
  margin-top: 1.4rem;
}

.index h2 {
  font: 600 0.72rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 0.4rem;
}

.index h2 a {
  color: var(--muted);
  text-decoration: none;
}

.index ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.index li a {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  gap: 0.4rem;
  padding: 0.15rem 0.4rem;
  margin-left: -0.4rem;
  border-radius: 4px;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.35;
}

.index li a:hover {
  background: var(--paper-2);
}

.index li a.current {
  background: var(--ink);
  color: var(--paper);
}

.index .mnemonic {
  font: 600 0.82rem/1.35 var(--mono);
}

.index .name {
  color: inherit;
  opacity: 0.8;
  font-size: 0.85rem;
}

main {
  padding: 2rem 2.5rem 4rem;
  min-width: 0;
}

.colophon {
  border-top: 1px solid var(--rule);
  padding: 1.2rem 1.5rem 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

@media (max-width: 820px) {
  .frame {
    grid-template-columns: minmax(0, 1fr);
  }

  .index {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--rule);
    padding: 1.25rem 1rem 2rem;
  }

  main {
    padding: 1.25rem 1rem 2.5rem;
  }

  .masthead {
    padding: 0.8rem 1rem;
  }
}

/* ---- prose ---------------------------------------------------------- */

.prose {
  max-width: 46rem;
}

.prose h1 {
  font-size: 2rem;
  line-height: 1.15;
  margin: 0.2rem 0 0.6rem;
  letter-spacing: -0.01em;
}

.prose h2 {
  font-size: 1.3rem;
  margin: 2.4rem 0 0.6rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
}

.prose h3 {
  font-size: 1.05rem;
  margin: 2rem 0 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.prose table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  text-align: left;
  vertical-align: top;
  padding: 0.35rem 0.6rem 0.35rem 0;
  border-bottom: 1px solid var(--rule);
}

.prose pre {
  background: var(--paper-2);
  padding: 0.8rem 1rem;
  border-radius: 6px;
  overflow-x: auto;
}

.kicker {
  margin: 0;
  font: 0.75rem/1.2 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.kicker a {
  color: var(--muted);
  text-decoration: none;
}

.sequence h1 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.8rem;
}

.sequence h1 .mnemonic {
  font-family: var(--mono);
  color: var(--accent);
  font-size: 0.9em;
}

.sequence h1 .name {
  font-weight: 400;
}

.lede {
  font-size: 1.15rem;
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1.2rem;
  font-size: 0.92rem;
  margin: 0 0 1.5rem;
}

.facts dt {
  color: var(--muted);
}

.facts dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.86rem;
}

/* ---- syntax diagram ------------------------------------------------- */

.syntax {
  margin: 0 0 1.25rem;
  overflow-x: auto;
}

.wire {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0 0 0.25rem;
  width: max-content;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
  border: 1.5px solid var(--ink);
  margin-left: -1.5px;
  font-family: var(--mono);
}

.tile:first-child {
  border-radius: 6px 0 0 6px;
  margin-left: 0;
}

.tile:last-child {
  border-radius: 0 6px 6px 0;
}

.tile .label {
  padding: 0.45rem 0.7rem 0.3rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.tile .hex {
  align-self: stretch;
  text-align: center;
  padding: 0.2rem 0.5rem 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  min-height: 1.5rem;
}

.tile.intro .label,
.tile.control .label {
  color: var(--accent);
}

.tile.param {
  border-style: dashed;
  background: var(--paper-2);
}

.tile.param .label {
  font-style: italic;
  font-weight: 400;
}

/* ---- tables of sequences -------------------------------------------- */

.catalog section h2 {
  border-top: 0;
  margin-top: 2rem;
}

.catalog section > p {
  color: var(--muted);
  margin-top: 0;
}

.sequences th {
  width: 6rem;
  font-family: var(--mono);
}

.sequences th a {
  font-weight: 600;
  text-decoration: none;
}

.sequences .syntax-inline code {
  background: none;
  padding: 0;
  white-space: nowrap;
}

.sequences .tally {
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
}

@media (max-width: 600px) {
  .sequences .syntax-inline {
    display: none;
  }
}

/* ---- verdicts ------------------------------------------------------- */

.pill {
  display: inline-block;
  font: 600 0.7rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.3em 0.55em;
  border-radius: 999px;
  white-space: nowrap;
}

.pill.pass,
.pill.fixed {
  color: var(--ok);
  background: var(--ok-wash);
}

.pill.fail {
  color: var(--bad);
  background: var(--bad-wash);
}

.pill.differs {
  color: var(--warn);
  background: var(--warn-wash);
}

/* ---- a validation case ---------------------------------------------- */

.vt-case > pre {
  margin: 0.4rem 0;
}

.load-error {
  color: var(--bad);
  font-size: 0.9rem;
}

.case {
  border: 1px solid var(--rule);
  border-left: 4px solid var(--ok);
  border-radius: 6px;
  margin: 0.6rem 0 1.5rem;
  background: color-mix(in srgb, var(--paper) 70%, var(--paper-2));
}

.case.fail {
  border-left-color: var(--bad);
}

.case.differs {
  border-left-color: var(--warn);
}

.case-body {
  display: grid;
  /* The input takes what the screens leave, but never less than enough to
     read a step; the screens give way and wrap rather than push it over. */
  grid-template-columns: minmax(14rem, 1fr) minmax(0, max-content);
  gap: 1rem 1.5rem;
  padding: 1rem 1rem 0.6rem;
}

@media (max-width: 760px) {
  .case-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

.case-body > * {
  min-width: 0;
}

.case h4 {
  margin: 0 0 0.4rem;
  font: 600 0.7rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.steps {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.84rem;
}

.step {
  counter-increment: step;
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr);
  grid-template-areas: "n head" "n bytes";
  column-gap: 0.6rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.5;
}

.step::before {
  content: counter(step);
  grid-area: n;
  color: var(--muted);
  text-align: right;
}

.step.done {
  opacity: 1;
}

.step.current {
  background: var(--paper-2);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* The source and its note share a line while they fit, and the note drops
   below a source too long to leave room beside it. */
.step .head {
  grid-area: head;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.6rem;
  min-width: 0;
}

.step .src {
  min-width: 0;
  background: none;
  padding: 0;
  font-size: 1em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.step .note {
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.95em;
}

.step .bytes {
  grid-area: bytes;
  color: var(--muted);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}

.screens {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
}

.screen {
  margin: 0;
}

.screen figcaption {
  font: 600 0.7rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.4rem;
  display: flex;
  gap: 0.5rem;
}

/* Room for the longest of "before any input", "after step N" and "after all
 * input", so that stepping does not resize the figure and shift the
 * expected screen beside it. */
.screen .when {
  display: inline-block;
  min-width: 16ch;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.grid {
  --cell-w: 1.5ch;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-w));
  grid-auto-rows: 1.45em;
  width: max-content;
  padding: 0.5rem 0.6rem;
  background: var(--term-bg);
  color: var(--term-fg);
  font: 1.05rem/1.45 var(--mono);
  border-radius: 5px;
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.15);
}

.grid.expected {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--rule);
}

.cell {
  text-align: center;
  white-space: pre;
  position: relative;
  /* Faint column guides, so blank cells can still be counted. */
  background-image: linear-gradient(to right, transparent calc(100% - 1px), rgb(127 127 127 / 0.12) 0);
}

.grid.expected .cell.blank::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px;
  border-radius: 50%;
  background: var(--rule);
}

.cell.bold {
  font-weight: 700;
}

.cell.italic {
  font-style: italic;
}

.cell.faint {
  opacity: 0.55;
}

.cell.invisible {
  color: transparent !important;
}

.cell.cursor {
  box-shadow: inset 0 0 0 2px var(--term-cursor);
}

.grid.expected .cell.cursor {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* A wrap is pending: the next character goes on the next line, so the
 * cursor is drawn leaning off the right edge of its cell. */
.cell.cursor.pending-wrap {
  box-shadow: inset -3px 0 0 var(--term-cursor);
}

.cell.miss {
  background-color: color-mix(in srgb, var(--bad) 45%, transparent);
  outline: 1px solid var(--bad);
  outline-offset: -1px;
}

.sent {
  flex-basis: 100%;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.8rem;
  margin: 0;
  font: 0.8rem/1.4 var(--mono);
}

.sent dt {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  padding-top: 0.15rem;
}

.sent dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.8rem;
  overflow-wrap: anywhere;
}

.sent .bytes,
.sent .none {
  color: var(--muted);
}

.case-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 0.6rem 1rem 0.8rem;
  border-top: 1px dashed var(--rule);
}

.verdict {
  font: 600 0.75rem/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ok);
}

.case.fail .verdict {
  color: var(--bad);
}

.case.differs .verdict {
  color: var(--warn);
}

.checks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.8rem;
  font: 0.78rem/1.3 var(--mono);
}

.checks li::before {
  content: "✓ ";
  color: var(--ok);
}

.checks li.bad::before {
  content: "✗ ";
  color: var(--bad);
}

.checks .what {
  color: var(--muted);
  margin-right: 0.35em;
}

.checks .got {
  color: var(--bad);
  margin-left: 0.5em;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
}

.stepper button {
  font: 0.8rem/1 var(--mono);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  min-width: 2rem;
  height: 1.9rem;
  cursor: pointer;
}

.stepper button:hover {
  border-color: var(--ink);
}

.stepper input[type="range"] {
  width: 7rem;
  accent-color: var(--accent);
}

.stepper .position {
  font: 0.78rem/1 var(--mono);
  color: var(--muted);
  min-width: 3.2rem;
  text-align: right;
}
