/* Red's website. Plain CSS, system fonts, no build step.
   The colours are Red's own looks, from crates/red/src/theme.rs: ember (a warm near-black) when the
   reader's system is dark, paper (warm white) when it is light. The one red is the caret's. */

:root {
  color-scheme: light dark;

  /* paper */
  --bg: oklch(0.985 0.006 85);
  --surface: oklch(0.962 0.007 85);
  --line: oklch(0.89 0.007 85);
  --fg: oklch(0.24 0.004 85);
  --muted: oklch(0.45 0.005 85);
  --faint: oklch(0.6 0.005 85);
  --accent: oklch(0.58 0.215 27);
  --added: oklch(0.945 0.04 150);
  --added-ink: oklch(0.45 0.14 150);
  --removed: oklch(0.945 0.04 25);
  --removed-ink: oklch(0.45 0.14 25);

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;

  --gutter: 16px;
  --page: 70rem;
  --text: 38rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* ember */
    --bg: oklch(0.168 0.005 50);
    --surface: oklch(0.205 0.006 55);
    --line: oklch(0.29 0.006 55);
    --fg: oklch(0.925 0.008 80);
    --muted: oklch(0.74 0.01 80);
    --faint: oklch(0.56 0.01 70);
    --accent: oklch(0.68 0.2 27);
    --added: oklch(0.245 0.04 150);
    --added-ink: oklch(0.8 0.13 150);
    --removed: oklch(0.245 0.04 25);
    --removed-ink: oklch(0.8 0.13 25);
  }
}

:root[data-theme="dark"] {
  --bg: oklch(0.168 0.005 50);
  --surface: oklch(0.205 0.006 55);
  --line: oklch(0.29 0.006 55);
  --fg: oklch(0.925 0.008 80);
  --muted: oklch(0.74 0.01 80);
  --faint: oklch(0.56 0.01 70);
  --accent: oklch(0.68 0.2 27);
  --added: oklch(0.245 0.04 150);
  --added-ink: oklch(0.8 0.13 150);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 1.0625rem/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  text-rendering: optimizeLegibility;
}

::selection {
  background: color-mix(in oklch, var(--fg) 18%, transparent);
}

img,
picture {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

.skip {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  padding: 0.5rem 0.75rem;
  background: var(--fg);
  color: var(--bg);
  border-radius: 6px;
  z-index: 10;
}

.skip:focus {
  top: 0.75rem;
}

.wrap {
  width: 100%;
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* Header */

.top {
  padding: 1.25rem 0;
}

.top .wrap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem 2rem;
  flex-wrap: wrap;
}

.mark {
  font: 600 1.375rem/1 var(--sans);
  letter-spacing: -0.01em;
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
}

/* The caret: Red's one red. It sits after the name as it does after typed text. */
.mark::after,
.caret::after {
  content: "";
  display: inline-block;
  width: 0.14em;
  height: 0.95em;
  margin-left: 0.08em;
  background: var(--accent);
  transform: translateY(0.12em);
}

.top nav ul {
  display: flex;
  gap: 0.25rem 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9375rem;
}

.top nav a {
  display: inline-block;
  padding: 0.5rem 0;
  text-decoration: none;
  color: var(--muted);
}

.top nav a:hover,
.top nav a[aria-current="page"] {
  color: var(--fg);
}

.top nav a[aria-current="page"] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.45em;
  text-decoration-thickness: 2px;
}

/* Type */

h1,
h2,
h3 {
  font-family: var(--sans);
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
  margin: 0;
}

h1 {
  font-size: clamp(2.125rem, 1.2rem + 4.2vw, 3.75rem);
  font-weight: 650;
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.125rem);
  font-weight: 620;
}

h3 {
  font-size: 1.125rem;
  font-weight: 620;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

p {
  margin: 0;
  text-wrap: pretty;
}

.lede {
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.3125rem);
  line-height: 1.5;
  color: var(--muted);
  max-width: 36rem;
}

.prose {
  max-width: var(--text);
}

.prose > * + * {
  margin-top: 1rem;
}

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

code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface);
}

/* Keys, as Red draws them. */
kbd {
  display: inline-block;
  padding: 0.05em 0.4em;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8125em;
  line-height: 1.4;
  white-space: nowrap;
}

pre {
  position: relative;
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.55;
  tab-size: 2;
}

pre[data-copy] {
  padding-right: 5rem;
}

pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

pre .todo,
.todo {
  color: var(--muted);
}

.copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  min-height: 2rem;
  padding: 0.2rem 0.6rem;
  font: 500 0.75rem/1 var(--sans);
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.copy:hover {
  color: var(--fg);
}

.copy:active {
  transform: scale(0.97);
}

/* Buttons */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 1.25rem;
  border-radius: 8px;
  background: var(--fg);
  color: var(--bg);
  font-weight: 550;
  text-decoration: none;
  transition: transform 120ms ease-out;
}

a[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.button:hover {
  background: color-mix(in oklch, var(--fg) 88%, var(--bg));
}

.button:active {
  transform: scale(0.98);
}

.fine {
  font-size: 0.875rem;
  color: var(--muted);
}

/* Layout of the sections */

main {
  display: block;
}

section {
  padding: clamp(3rem, 2rem + 5vw, 6rem) 0 0;
}

.hero {
  padding-top: clamp(1.5rem, 1rem + 3vw, 4rem);
}

.hero h1 {
  max-width: 15ch;
}

.hero .lede {
  margin-top: 1.5rem;
}

.hero .actions {
  margin-top: 2rem;
}

.hero .fine {
  margin-top: 1.25rem;
}

.shot {
  margin: clamp(2rem, 1.5rem + 2.5vw, 3.5rem) 0 0;
}

.shot img {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.shot figcaption {
  margin-top: 0.6rem;
  font-size: 0.875rem;
  color: var(--muted);
  max-width: var(--text);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem 3rem;
  align-items: start;
}

@media (min-width: 52rem) {
  .split {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  }
  .split.reverse {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  }
  .split.reverse > :first-child {
    order: 2;
  }
  .split .shot {
    margin-top: 0.4rem;
  }
}

.section-head > * + * {
  margin-top: 1rem;
}

/* What was measured: a name, then the number. */

.numbers {
  display: grid;
  margin: 2rem 0 0;
  border-top: 1px solid var(--line);
}

.numbers > div {
  display: grid;
  gap: 0.2rem 2rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

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

.numbers dd {
  margin: 0;
}

.numbers .figure {
  font: 600 1.375rem/1.2 var(--mono);
  letter-spacing: -0.02em;
}

.numbers .figure small {
  font: 400 0.875rem/1.4 var(--sans);
  letter-spacing: 0;
  color: var(--muted);
}

@media (min-width: 40rem) {
  .numbers > div {
    grid-template-columns: 14rem minmax(0, 1fr);
    align-items: baseline;
  }
}

/* A list that reads like the editor's gutter. */

.lines {
  margin: 2rem 0 0;
  padding: 0;
  list-style: none;
  counter-reset: line;
  max-width: 46rem;
}

.lines > li {
  counter-increment: line;
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  padding: 0.9rem 0;
  border-top: 1px solid var(--line);
}

.lines > li::before {
  content: counter(line);
  font: 400 0.8125rem/2 var(--mono);
  color: var(--faint);
  text-align: right;
  padding-right: 1rem;
  user-select: none;
}

.lines h3 {
  display: inline;
}

.lines p {
  color: var(--muted);
  margin-top: 0.15rem;
}

.lines a {
  color: var(--fg);
}

/* Feature page */

.contents {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 2rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9375rem;
  max-width: 46rem;
}

.contents a {
  display: inline-block;
  padding: 0.4rem 0;
  color: var(--muted);
  text-decoration: none;
}

.contents a:hover {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.feature h2 {
  scroll-margin-top: 1rem;
}

.feature .prose {
  margin-top: 1rem;
}

.facts {
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
  max-width: var(--text);
}

.facts li {
  position: relative;
  padding: 0.35rem 0 0.35rem 1.25rem;
  color: var(--muted);
}

.facts li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1.05em;
  width: 0.5rem;
  height: 1px;
  background: var(--faint);
}

.facts strong {
  color: var(--fg);
  font-weight: 560;
}

.note {
  margin-top: 1.25rem;
  padding: 0.75rem 1rem;
  max-width: var(--text);
  border-left: 2px solid var(--accent);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
  font-size: 0.9375rem;
}

/* Download */

.downloads {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  margin: 2.5rem 0 0;
}

@media (min-width: 52rem) {
  .downloads {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.download {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.download p {
  color: var(--muted);
  font-size: 0.9375rem;
}

.download .button {
  max-width: 100%;
  overflow-wrap: anywhere;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  line-height: 1.3;
  font-size: 0.9375rem;
  align-self: flex-start;
  margin-top: auto;
}

/* Tables (the docs page) */

.table {
  width: 100%;
  margin: 1.25rem 0 0;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table caption {
  text-align: left;
  color: var(--muted);
  padding-bottom: 0.5rem;
}

.table th,
.table td {
  padding: 0.55rem 1rem 0.55rem 0;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: baseline;
}

.table th {
  font-weight: 500;
  white-space: nowrap;
}

.table td:last-child {
  color: var(--muted);
}

.scroll {
  overflow-x: auto;
}

/* Footer */

.foot {
  margin-top: clamp(4rem, 3rem + 6vw, 8rem);
  padding: 2rem 0 3rem;
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
  color: var(--muted);
}

.foot .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem 2rem;
}

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

.foot a {
  display: inline-block;
  padding: 0.35rem 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

@media (hover: none) {
  .button:hover {
    background: var(--fg);
  }
}
