/* araara design system — the ONE stylesheet.
   Palette inspired by Ara ararauna, the blue-and-gold macaw. */

:root {
  color-scheme: light;
  --ink: #1b2a41;
  --ink-muted: #51607a;
  --paper: #fcfbf7;
  --surface: #ffffff;
  --line: #e4e1d6;
  --blue: #16335e;
  --blue-deep: #0e2344;
  --blue-bright: #2e6bb0;
  /* Heading / brand-blue text on the paper surface. Kept separate from
     --blue (which also serves as a dark *background* in the hero gradient)
     so the dark theme can lighten headings without touching the hero. */
  --heading: var(--blue);
  --gold: #f2b705;
  --gold-deep: #d99e00;
  --code-bg: #101c33;
  --code-ink: #d9e4f5;
  --code-dim: #8fa3c4;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(20 33 61 / 0.06), 0 8px 24px rgb(20 33 61 / 0.06);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo,
    Consolas, monospace;
}

/* ---------- dark theme (follows the OS / browser setting) ----------
   There is no manual toggle: the palette simply tracks
   `prefers-color-scheme`. Only the paper-surface tokens
   flip. The brand-dark surfaces (header, hero, footer, code blocks) are
   already dark in light mode and stay dark here by design. */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #d7e0f0;
    --ink-muted: #9fb0cc;
    --paper: #0c1322;
    --surface: #131d33;
    --line: #29344e;
    --blue-bright: #6ea8e6;
    --heading: #cddcff;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 28px rgb(0 0 0 / 0.45);
  }
}

/* ---------- base ---------- */

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

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

main {
  flex: 1;
  width: 100%;
  padding-block: 3rem 5rem;
  --space: 5rem;
}

h1,
h2,
h3 {
  line-height: 1.15;
  color: var(--heading);
  margin: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.1rem, 4.5vw, 3.1rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
}

h3 {
  font-size: 1.15rem;
}

p {
  margin: 0;
}

a {
  color: var(--blue-bright);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--gold-deep);
}

ul,
ol,
dl {
  margin: 0;
  padding: 0;
}

img {
  max-width: 100%;
  display: block;
}

::selection {
  background: var(--gold);
  color: var(--blue-deep);
}

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

/* ---------- layout primitives ---------- */

.center {
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

.stack > * + * {
  margin-top: var(--space, 1rem);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, 0.75rem);
}

.grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
}

/* ---------- site header ---------- */

.site-header {
  background: var(--blue-deep);
  border-bottom: 3px solid var(--gold);
}

.site-nav {
  justify-content: space-between;
  padding-block: 0.9rem;
}

.site-nav ul {
  list-style: none;
  --gap: 1.5rem;
}

.site-nav a {
  color: #e8edf7;
  text-decoration: none;
  font-weight: 500;
}

.site-nav a:hover {
  color: var(--gold);
}

.site-nav a[aria-current="page"] {
  color: var(--gold);
  border-bottom: 2px solid var(--gold);
  padding-bottom: 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1.45rem;
  font-weight: 800;
  color: #fff !important;
  letter-spacing: 0.01em;
}

.brand:hover {
  color: var(--gold) !important;
}

/* The logo is black line art; invert it to render light on the dark
   header. The favicon keeps its original black for browser tabs. */
.brand img {
  filter: invert(1);
}

/* ---------- hero ---------- */

.hero {
  display: grid;
  gap: 2.5rem;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  align-items: center;
  background: linear-gradient(140deg, var(--blue-deep) 0%, var(--blue) 60%, #1d4377 100%);
  color: #e8edf7;
  border-radius: calc(var(--radius) * 1.5);
  padding: clamp(1.5rem, 5vw, 3.5rem);
  box-shadow: var(--shadow);
}

.hero h1 {
  color: #fff;
}

.hero .lede {
  color: #c3d0e5;
}

.hero .kicker {
  color: var(--gold);
}

.hero .code-block {
  margin: 0;
  box-shadow: 0 12px 32px rgb(8 16 32 / 0.45);
}

.hero-copy {
  --space: 1.25rem;
}

/* ---------- text styles ---------- */

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gold-deep);
}

.lede {
  font-size: 1.2rem;
  color: var(--ink-muted);
  max-width: 60ch;
}

.section-heading,
.page-heading {
  --space: 0.5rem;
}

.prose {
  --space: 1.5rem;
}

.prose p {
  max-width: 70ch;
}

.prose h2 {
  margin-top: 2.5rem;
}

/* ---------- buttons & pills ---------- */

.btn {
  display: inline-block;
  padding: 0.6rem 1.3rem;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  border: 2px solid transparent;
}

.btn--primary {
  background: var(--gold);
  color: var(--blue-deep);
}

.btn--primary:hover {
  background: var(--gold-deep);
  color: var(--blue-deep);
}

.btn--ghost {
  border-color: currentColor;
  color: inherit;
}

.btn--ghost:hover {
  color: var(--gold-deep);
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgb(242 183 5 / 0.18);
  color: var(--heading);
  border: 1px solid rgb(217 158 0 / 0.4);
  font-family: var(--font-mono);
}

.pill--muted {
  background: rgb(20 33 61 / 0.05);
  border-color: var(--line);
  color: var(--ink-muted);
}

/* ---------- cards ---------- */

.card,
.lib-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  --space: 0.75rem;
}

.lib-card {
  border-top: 3px solid var(--gold);
}

/* ---------- home examples ---------- */

.examples-grid {
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
}

/* The screenshot runs flush to the card edges; the text sits in a padded
   body below it. */
.example-card {
  padding: 0;
  overflow: hidden;
}

.example-shot {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  object-fit: cover;
  border-bottom: 1px solid var(--line);
  background: var(--code-bg);
}

.example-body {
  padding: 1.5rem;
  --space: 0.75rem;
}

.example-body p {
  color: var(--ink-muted);
}

.lib-card header {
  justify-content: space-between;
}

.lib-card h3 a {
  color: var(--heading);
  text-decoration: none;
}

.lib-card h3 a:hover {
  color: var(--gold-deep);
}

.lib-card p {
  color: var(--ink-muted);
}

.showcase {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: var(--radius);
  padding: 2rem;
  --space: 1rem;
}

.showcase p {
  max-width: 70ch;
}

/* ---------- code ---------- */

.code-block {
  margin: 0;
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.85rem;
}

/* API reference: definition blocks and headings carry odoc-style anchor
   ids (#val-foo, #type-t). Give targets room so an anchor jump doesn't
   land flush against the top of the viewport. */
.doc-body [id] {
  scroll-margin-top: 1.5rem;
}

.code-block figcaption {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--code-dim);
  background: rgb(255 255 255 / 0.06);
  border-bottom: 1px solid rgb(255 255 255 / 0.08);
  padding: 0.5rem 1rem;
}

.code-block pre {
  margin: 0;
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
}

.code-block code {
  font-family: var(--font-mono);
  color: var(--code-ink);
}

.shell-line {
  margin: 0;
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 0.8rem 1.25rem;
  overflow-x: auto;
}

.shell-line code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--gold);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-ligatures: none;
}

/* syntax highlighting tokens (server-side) */

.code-block .tok-kw {
  color: #fbbf24;
}

.code-block .tok-str {
  color: #a8d8a8;
}

.code-block .tok-com {
  color: #8fa3c4;
  font-style: italic;
}

.code-block .tok-mod {
  color: #8ec8ff;
}

.code-block .tok-num {
  color: #f2a6c8;
}

.code-block .tok-attr {
  color: #fbbf24;
  font-style: italic;
}

/* ---------- note callout ---------- */

.note {
  border-left: 4px solid var(--blue-bright);
  background: rgb(46 107 176 / 0.07);
  padding: 1rem 1.25rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  --space: 0.75rem;
}

.note p {
  max-width: 70ch;
}

/* ---------- definition lists ---------- */

.term-list {
  display: grid;
  gap: 1rem;
}

.term-list dt {
  font-weight: 700;
  color: var(--heading);
}

.term-list dd {
  margin: 0.15rem 0 0;
  color: var(--ink-muted);
  max-width: 70ch;
}

/* ---------- generic lists in prose ---------- */

.prose ul {
  list-style: disc;
  padding-left: 1.25rem;
  --space: 0.75rem;
}

.prose li {
  max-width: 70ch;
}

/* ---------- documentation ---------- */

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

@media (max-width: 56rem) {
  .docs-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Lead with the content; the documentation index follows it as a
     plain, full-width block rather than a sticky full-height sidebar. */
  .docs-layout > .doc-page {
    order: 1;
  }

  .docs-layout > .docs-nav {
    order: 2;
    position: static;
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
  }
}

.docs-nav {
  position: sticky;
  top: 1.5rem;
  font-size: 0.95rem;
  /* Scroll the nav itself when it is taller than the viewport, so a long
     page's TOC stays fully reachable. */
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.5rem;
}

.docs-nav ul {
  list-style: none;
  display: grid;
  gap: 0.35rem;
}

.docs-nav-group {
  margin-top: 1.25rem;
}

.docs-nav-group > span {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 0.5rem;
}

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

.docs-nav a:hover {
  color: var(--gold-deep);
}

.docs-nav a[aria-current="page"] {
  color: var(--heading);
  font-weight: 700;
  border-left: 3px solid var(--gold);
  padding-left: 0.5rem;
  margin-left: -0.7rem;
}

/* API reference nav: a collapsible package tree. Each package is a
   <details> (collapsed by default, the current one open); the current
   module folds out its own value/type/exception entries. */
.docs-nav details {
  margin-top: 0.6rem;
}

.docs-nav summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  color: var(--ink-muted);
}

.docs-nav summary::-webkit-details-marker {
  display: none;
}

.docs-nav summary::before {
  content: "\25b8"; /* ▸ */
  display: inline-block;
  width: 1em;
  color: var(--ink-muted);
  transition: transform 0.15s ease;
}

.docs-nav details[open] > summary::before {
  transform: rotate(90deg);
}

.docs-nav summary a {
  color: inherit;
}

/* Indent the nested levels (modules under a package, entries under a
   module) with a hairline guide. */
.docs-nav details > ul,
.docs-nav .api-defs {
  margin: 0.4rem 0 0.2rem 0.85rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--line);
}

.docs-nav .api-defs {
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.docs-nav .api-defs a {
  color: var(--ink-muted);
}

.docs-nav .api-defs a:hover {
  color: var(--gold-deep);
}

.doc-page {
  --space: 2.5rem;
}

.doc-section {
  --space: 1.25rem;
}

.doc-sub {
  --space: 1rem;
  margin-top: 2rem;
}

.doc-sub h3 {
  font-size: 1.05rem;
}

.doc-section .prose {
  --space: 1rem;
}

/* Rendered Markdown body (cmarkit output). The markdown emits plain
   h2/h3/p/ul/blockquote/figure, so style them here to match the rest. */
.doc-body > * + * {
  margin-top: 1.1rem;
}

/* Embedded demo video (a raw <figure class="doc-video"> in the Markdown). */
.doc-body .doc-video {
  margin: 1.75rem 0;
}

.doc-body .doc-video video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #000;
}

.doc-body .doc-video figcaption {
  margin-top: 0.6rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.doc-body h2 {
  margin-top: 2.75rem;
}

.doc-body h3 {
  margin-top: 2rem;
  font-size: 1.05rem;
}

.doc-body p,
.doc-body li {
  max-width: 70ch;
}

.doc-body ul,
.doc-body ol {
  padding-left: 1.25rem;
  display: grid;
  gap: 0.4rem;
}

.doc-body ul {
  list-style: disc;
}

.doc-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  font-variant-ligatures: none;
}

/* Tables (cmarkit's non-strict GFM table extension). The benchmark table is
   wide, so let it scroll horizontally rather than overflow the layout. */
.doc-body table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 1.25rem 0;
}

.doc-body th,
.doc-body td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}

.doc-body thead th {
  background: rgb(46 107 176 / 0.08);
  color: var(--heading);
}

.doc-body tbody tr:nth-child(even) {
  background: rgb(20 33 61 / 0.03);
}

/* A blockquote is our note/callout. */
.doc-body blockquote {
  margin: 1.5rem 0;
  border-left: 4px solid var(--blue-bright);
  background: rgb(46 107 176 / 0.07);
  padding: 0.4rem 1.25rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--ink-muted);
}

.doc-body blockquote p {
  margin: 0.6rem 0;
}

/* in-page table of contents nested under the current doc link */

.docs-nav .docs-toc {
  margin: 0.4rem 0 0.6rem 0;
  padding-left: 0.85rem;
  border-left: 1px solid var(--line);
  gap: 0.3rem;
  font-size: 0.85rem;
}

.docs-nav .docs-toc a {
  color: var(--ink-muted);
}

.docs-nav .docs-toc a:hover {
  color: var(--gold-deep);
}

/* Flat TOC list: indent h3 (sub) entries under their h2. */
.docs-nav .docs-toc .docs-toc-sub {
  padding-left: 1rem;
  font-size: 0.95em;
}

.docs-nav .docs-toc .docs-toc-sub a {
  color: var(--ink-muted);
  opacity: 0.85;
}

.docs-nav .docs-toc-subs {
  margin: 0.3rem 0 0.3rem 0;
  padding-left: 0.85rem;
  gap: 0.25rem;
  font-size: 0.8rem;
}

/* ---------- acknowledgements ---------- */

.credits-grid {
  list-style: none;
  display: grid;
  gap: 0.9rem 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}

.credits-grid li {
  line-height: 1.3;
}

.credits-grid a {
  font-family: var(--font-mono);
  font-weight: 600;
  text-decoration: none;
}

.credits-grid .credits-authors {
  display: block;
  color: var(--ink-muted);
  font-size: 0.82rem;
}

/* ---------- footer ---------- */

.site-footer {
  background: var(--blue-deep);
  color: #c3d0e5;
  border-top: 3px solid var(--gold);
  padding-block: 2rem;
  margin-top: 4rem;
  font-size: 0.95rem;
}

.site-footer .cluster {
  justify-content: space-between;
}

.site-footer a {
  color: var(--gold);
}

.site-footer ul {
  list-style: none;
  --gap: 1.25rem;
}

/* ---------- easter-egg toast ----------
   Shown by the lone script (lib/araara_www_web/easter_egg.ml) when you type
   "araara" or tap the footer five times. Pinned bottom-centre, themed from
   the same tokens as everything else so it follows light/dark. */

.egg-toast {
  position: fixed;
  z-index: 100;
  inset-block-end: 1.25rem;
  inset-inline: 1rem;
  margin-inline: auto;
  max-width: 30rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  cursor: pointer;
  animation: egg-toast-in 0.35s ease;
}

.egg-toast__title {
  display: block;
  color: var(--heading);
  font-size: 1.1rem;
  margin-bottom: 0.4rem;
}

.egg-toast ul {
  list-style: none;
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.egg-toast--out {
  animation: egg-toast-out 0.4s ease forwards;
}

@keyframes egg-toast-in {
  from {
    opacity: 0;
    transform: translateY(1rem);
  }
}

@keyframes egg-toast-out {
  to {
    opacity: 0;
    transform: translateY(1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .egg-toast,
  .egg-toast--out {
    animation: none;
  }
}

/* ---------- phones ----------
   Most of the layout is already fluid (clamp() type, auto-fit grids,
   the docs sidebar collapse above). This block tightens the header and
   the generous desktop spacing so a phone screen reads densely. */

@media (max-width: 40rem) {
  /* Section gaps and page padding are sized for wide screens; on a phone
     5rem of air between sections wastes most of the viewport. */
  main {
    padding-block: 1.75rem 3rem;
    --space: 3rem;
  }

  /* Center the brand and nav links and let them wrap onto two rows
     without the desktop space-between pushing them to the edges. */
  .site-nav {
    justify-content: center;
    row-gap: 0.4rem;
  }

  .site-nav ul {
    --gap: 1.1rem;
    justify-content: center;
  }

  .hero {
    gap: 1.75rem;
  }

  .showcase {
    padding: 1.5rem;
  }

  .site-footer .cluster,
  .site-footer ul {
    --gap: 0.9rem;
  }
}
