/*
 * "Night Programme": see docs/brand.md. The same tokens as the app and the site, as hex here because
 * nothing needs the preset's HSL triples. `test/brand.test.ts` compares them with the table in the brand
 * doc, and `npm run check:contrast` checks the pairs used. Fonts are copied from apps/app/public/fonts.
 */
@font-face {
  font-family: "Instrument Serif";
  src: url("/fonts/instrument-serif-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  size-adjust: 112%;
}
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "DM Mono";
  src: url("/fonts/dm-mono-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Archivo Fallback";
  src: local("Arial");
  size-adjust: 101%;
  ascent-override: 87%;
  descent-override: 21%;
  line-gap-override: 0%;
}
@font-face {
  font-family: "Instrument Serif Fallback";
  src: local("Times New Roman");
  size-adjust: 96%;
  ascent-override: 102%;
  descent-override: 32%;
  line-gap-override: 0%;
}

:root {
  --background: #0c1311;
  --card: #131c19;
  --secondary: #1b2622;
  --foreground: #f3eee2;
  --muted-foreground: #a9b1a3;
  --border: #2b3631;
  --input: #66746c;
  --signal: #f0683c;
  --paper: #f3eee2;
  --paper-foreground: #10201a;
  --paper-muted: #4d5a52;
  --paper-signal: #b23a14;
  --radius: 3px;
  --ease-precise: cubic-bezier(0.2, 0, 0, 1);
  --display: "Instrument Serif", "Instrument Serif Fallback", Georgia, serif;
  --sans: "Archivo", "Archivo Fallback", Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  font-synthesis: none;
  scroll-padding-top: 1.5rem;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

main {
  flex: 1;
}

h1,
h2 {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.5rem, 7vw, 3.5rem);
  margin: 1.25rem 0 0.5rem;
}

a {
  color: inherit;
  text-decoration-color: var(--signal);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 2px;
}

a:focus-visible,
input:focus-visible,
.table-scroll:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: var(--radius);
}

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

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: var(--paper);
  color: var(--paper-foreground);
  border-radius: var(--radius);
}

.skip:focus {
  top: 0.5rem;
}

.wrap {
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.narrow {
  max-width: 46rem;
}

.tick-rule {
  height: 7px;
  border-top: 1px solid var(--border);
  background-image: repeating-linear-gradient(
    to right,
    rgb(243 238 226 / 22%) 0 1px,
    transparent 1px 12px
  );
}

.label {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--signal);
  line-height: 1.4;
  margin: 0;
}

.muted {
  color: var(--muted-foreground);
}

.small {
  font-size: 0.875rem;
}

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

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  min-height: 2.75rem;
}

.mark {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
}

.needle {
  stroke: var(--signal);
}

.logo-help {
  color: var(--muted-foreground);
  font-weight: 500;
  padding-left: 0.625rem;
  border-left: 1px solid var(--border);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.lang {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-decoration: none;
  padding: 0.75rem;
}

.lang:hover {
  color: var(--foreground);
}

.button-outline {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 120ms var(--ease-precise);
  white-space: nowrap;
}

.button-outline:hover {
  border-color: var(--foreground);
}

/* Hero */
.hero {
  padding: 2.5rem 0 2rem;
}

/* Search */
.search {
  margin: 0 0 1.5rem;
}

.search input {
  width: 100%;
  min-height: 3rem;
  padding: 0 0.875rem;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius);
  /* 16px or more: iOS zooms the page into a smaller field. */
  font: 400 1rem var(--sans);
  appearance: none;
}

.search input::placeholder {
  color: var(--muted-foreground);
  opacity: 1;
}

.results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.results[hidden] {
  display: none;
}

.results li + li {
  border-top: 1px solid var(--border);
}

.results a {
  display: block;
  padding: 0.75rem 0.875rem;
  text-decoration: none;
}

.results a:hover,
.results a:focus-visible {
  background: var(--secondary);
}

.result-note {
  padding: 0.75rem 0.875rem;
  color: var(--muted-foreground);
  font-size: 0.9375rem;
}

/* The entry list: categories on the home page, articles everywhere else. */
.section-label {
  margin: 1rem 0 1rem;
}

.categories {
  list-style: none;
  margin: 0 0 2.5rem;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.categories a {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  column-gap: 0.5rem;
  height: 100%;
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 120ms var(--ease-precise);
}

.categories a:hover {
  border-color: var(--input);
}

.race-number {
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--signal);
  grid-row: 1 / span 3;
  padding-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.category-name {
  font-family: var(--display);
  font-size: 1.5rem;
  line-height: 1.2;
}

.count {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin-top: 0.5rem;
}

.entries {
  list-style: none;
  margin: 0 0 2rem;
  padding: 0;
  border-top: 1px solid var(--border);
}

.entries li {
  border-bottom: 1px solid var(--border);
}

.entries a {
  display: block;
  padding: 0.875rem 0;
  text-decoration: none;
}

.entries a:hover .entry-title {
  text-decoration: underline;
  text-decoration-color: var(--signal);
  text-underline-offset: 3px;
}

.entry-title {
  display: block;
  font-weight: 500;
}

.entry-note {
  display: block;
  color: var(--muted-foreground);
  font-size: 0.9375rem;
  line-height: 1.45;
}

/* Article */
.page-top {
  padding-top: 1rem;
}

.crumbs {
  font-size: 0.875rem;
  color: var(--muted-foreground);
  min-height: 2.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.crumbs a {
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--foreground);
  text-decoration: underline;
}

.article-grid {
  display: grid;
  gap: 3rem;
}

.article {
  min-width: 0;
  max-width: 44rem;
}

.updated {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin: 0 0 1.5rem;
}

.toc ul {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.toc li {
  padding: 0.3125rem 0;
  font-size: 0.9375rem;
  line-height: 1.35;
}

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

.toc a:hover {
  color: var(--foreground);
  text-decoration: underline;
}

.toc-inline {
  padding: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 2rem;
}

.toc-side {
  display: none;
}

.prose h2 {
  font-size: 2rem;
  margin: 2.25rem 0 0.75rem;
}

.prose h3 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 1.5rem 0 0.25rem;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote {
  margin: 0 0 1rem;
}

.prose ul,
.prose ol {
  padding-left: 1.375rem;
}

.prose li {
  margin-bottom: 0.375rem;
}

.prose li::marker {
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

.prose strong {
  font-weight: 600;
}

.prose blockquote {
  padding: 0.75rem 1rem;
  background: var(--card);
  border-left: 2px solid var(--signal);
  border-radius: var(--radius);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--secondary);
  padding: 0.0625rem 0.3125rem;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.table-scroll {
  overflow-x: auto;
  margin: 0 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  min-width: 6.5rem;
}

th {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  background: var(--card);
}

tr:last-child td {
  border-bottom: 0;
}

.related h2 {
  font-size: 1.75rem;
  margin: 2.5rem 0 0.75rem;
}

/* The paddock pass: the one light surface, used only for the way out. */
.stuck {
  background: var(--paper);
  color: var(--paper-foreground);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 2rem 0 3rem;
}

.stuck h2 {
  font-size: 1.75rem;
  margin: 0 0 0.25rem;
}

.stuck p {
  margin: 0 0 0.75rem;
  color: var(--paper-muted);
}

.stuck-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin: 0;
}

.stuck-mail,
.stuck-chat {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  font-weight: 600;
  color: var(--paper-foreground);
  text-decoration-color: var(--paper-signal);
  overflow-wrap: anywhere;
}

.stuck a:focus-visible {
  outline-color: var(--paper-signal);
}

/* Footer */
.site-footer {
  margin-top: 1rem;
  padding-bottom: 2.5rem;
  font-size: 0.875rem;
}

.footer-columns {
  display: grid;
  gap: 2rem;
  padding: 2rem 0 1.5rem;
}

.footer-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}

.footer-list li a {
  display: inline-block;
  padding: 0.375rem 0;
  color: var(--muted-foreground);
  text-decoration: none;
}

.footer-list li a:hover {
  color: var(--foreground);
  text-decoration: underline;
}

.fine {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  margin: 0.5rem 0 0;
  max-width: 46rem;
}

.not-found-second {
  font-size: clamp(2rem, 6vw, 2.75rem);
  margin: 3rem 0 0.5rem;
}

@media (max-width: 26rem) {
  /* The wordmark's tracking is wide: on the smallest phones the help tag gives way first. */
  .logo-help {
    display: none;
  }
  .button-outline {
    padding: 0 0.75rem;
  }
}

@media (min-width: 40rem) {
  .categories {
    grid-template-columns: repeat(2, 1fr);
  }
  .footer-list.two {
    columns: 2;
    column-gap: 2rem;
  }
  .footer-columns {
    grid-template-columns: 2fr 1fr;
  }
}

@media (min-width: 64rem) {
  .article-grid:not(.no-toc) {
    grid-template-columns: minmax(0, 44rem) 15rem;
    justify-content: space-between;
  }
  .toc-inline {
    display: none;
  }
  .toc-side {
    display: block;
    padding-top: 2rem;
  }
  .toc-side .toc {
    position: sticky;
    top: 1.5rem;
  }
  .categories {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  ::before,
  ::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
