/* morph — richtel.net
   Palette: lichen paper, slate ink, beech-green links, one gorse-yellow mark. */

@font-face { font-family: "Archivo"; src: url("fonts/archivo-var.woff2") format("woff2-variations"), url("fonts/archivo-var.woff2") format("woff2");
  font-weight: 100 900; font-stretch: 62% 125%; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("fonts/literata-var.woff2") format("woff2");
  font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Literata"; src: url("fonts/literata-var-italic.woff2") format("woff2");
  font-weight: 200 900; font-style: italic; font-display: swap; }

:root {
  --paper:   #edf1ee;
  --surface: #f8faf8;
  --ink:     #1b2731;
  --muted:   #55646b;
  --line:    #c7d2cd;
  --accent:  #2d6a55;
  --accent-ink: #1f4d3d;
  --mark:    #e9b829;

  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Literata", Georgia, "Times New Roman", serif;

  --measure: 68ch;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:   #131a1e;
    --surface: #1a2328;
    --ink:     #e3e9e6;
    --muted:   #9aa8a3;
    --line:    #2f3b40;
    --accent:  #7fc4a7;
    --accent-ink: #a6dbc4;
  }
}
:root[data-theme="dark"] {
  --paper: #131a1e; --surface: #1a2328; --ink: #e3e9e6; --muted: #9aa8a3;
  --line: #2f3b40; --accent: #7fc4a7; --accent-ink: #a6dbc4;
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: clamp(1.0625rem, 0.98rem + 0.3vw, 1.1875rem);
  line-height: 1.65;
  font-optical-sizing: auto;
}

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

a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-ink); text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--mark); outline-offset: 2px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.site-header .bar {
  max-width: 72rem;
  margin: 0 auto;
  padding: 14px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 32px;
}
.brand {
  font-family: var(--font-display);
  font-weight: 750;
  font-stretch: 112%;
  font-variation-settings: "wdth" 112;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  line-height: 1;
}
.brand:hover { color: var(--ink); }

.site-nav ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 4px 22px;
}
.site-nav a {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 3px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current] { color: var(--ink); border-bottom-color: var(--mark); }

/* ---------- Page layout ---------- */

main { display: block; }

.page {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(28px, 5vw, 64px) var(--gutter) 72px;
  display: grid;
  grid-template-columns: minmax(0, var(--measure)) minmax(0, 1fr);
  column-gap: clamp(32px, 6vw, 88px);
}
.page > * { grid-column: 1; }
.page > .aside { grid-column: 2; grid-row: 1 / span 20; }

@media (max-width: 900px) {
  .page { grid-template-columns: minmax(0, 1fr); }
  .page > .aside { grid-column: 1; grid-row: auto; }
}

.crumbs {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 18px;
}
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0 6px; }
.crumbs li + li::before { content: "/"; margin-right: 6px; color: var(--line); }
.crumbs a { color: var(--muted); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 {
  font-size: clamp(2.2rem, 1.4rem + 3.2vw, 3.6rem);
  font-weight: 760;
  font-variation-settings: "wdth" 88;
  font-stretch: 88%;
  margin: 0 0 14px;
  letter-spacing: -0.025em;
}
.dek {
  font-size: 1.15em;
  color: var(--muted);
  margin: 0 0 36px;
  max-width: 56ch;
}
.prose .byline { font-family: var(--font-display); font-size: 0.95rem; color: var(--muted); margin: -12px 0 28px; }
.prose .note { margin-bottom: 28px; }

.prose h2 {
  font-size: clamp(1.4rem, 1.1rem + 1vw, 1.8rem);
  font-weight: 700;
  margin: 2.2em 0 0.5em;
  scroll-margin-top: 16px;
}
.prose h3 { font-size: 1.2rem; font-weight: 680; margin: 1.8em 0 0.4em; scroll-margin-top: 16px; }
.prose h4 { font-size: 1.05rem; font-weight: 650; margin: 1.5em 0 0.3em; }
.prose p, .prose ul, .prose ol, .prose table, .prose blockquote { margin: 0 0 1.05em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: 0.2em 0; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 650; }
.prose blockquote {
  margin-left: 0; padding: 2px 0 2px 18px;
  border-left: 3px solid var(--mark);
  color: var(--muted);
}
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }

.prose table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-display);
  font-size: 0.93rem;
  font-variant-numeric: tabular-nums;
}
.prose th, .prose td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-weight: 650; }
.table-wrap { overflow-x: auto; }

.note {
  font-family: var(--font-display);
  font-size: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 16px;
  color: var(--muted);
}

/* Figures: photos get a little surface so a missing image never looks broken */
.prose figure { margin: 1.8em 0; }
.prose figure img, .gallery img {
  background: var(--surface);
  border-radius: 4px;
}
.prose figcaption {
  font-family: var(--font-display);
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 8px;
}
.prose figure.wide { margin-left: 0; margin-right: 0; }
.prose figure.equation img { background: #fff; padding: 10px; border-radius: 4px; }
.prose figure.diagram img { background: #fff; padding: 12px; border-radius: 4px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 12px;
  margin: 1.6em 0;
}
.gallery a { display: block; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }

/* ---------- Aside: section menu and on-this-page ---------- */

.aside { font-family: var(--font-display); font-size: 0.95rem; }
.aside .panel { position: sticky; top: 24px; }
.aside h2 {
  font-size: 0.95rem; font-weight: 650; color: var(--muted);
  margin: 0 0 10px; letter-spacing: 0;
}
.aside ul { list-style: none; margin: 0 0 32px; padding: 0; }
.aside li { margin: 0; }
.aside a {
  display: block; padding: 5px 0 5px 12px;
  border-left: 2px solid var(--line);
  color: var(--ink); text-decoration: none; line-height: 1.35;
}
.aside a:hover { border-left-color: var(--accent); color: var(--accent); }
.aside a[aria-current] { border-left-color: var(--mark); font-weight: 650; }
.aside ul ul { margin: 0; }
.aside ul ul a { padding-left: 26px; font-size: 0.9rem; color: var(--muted); }

@media (max-width: 900px) {
  .aside .panel { position: static; }
  .aside { border-top: 1px solid var(--line); padding-top: 28px; margin-top: 40px; }
}

/* ---------- Child-page list on section pages ---------- */

.children { list-style: none; padding: 0; margin: 2.2em 0; }
.children li { border-top: 1px solid var(--line); }
.children li:last-child { border-bottom: 1px solid var(--line); }
.children a {
  display: grid; gap: 2px; padding: 16px 0;
  text-decoration: none; color: var(--ink);
}
.children .t {
  font-family: var(--font-display); font-weight: 680; font-size: 1.2rem;
  color: var(--accent);
}
.children a:hover .t { text-decoration: underline; text-underline-offset: 0.18em; }
.children .d { color: var(--muted); font-size: 0.98rem; }

.updir {
  font-family: var(--font-display); font-size: 0.95rem;
  margin-top: 48px;
}

/* ---------- Home ---------- */

.hero {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(36px, 7vw, 96px) var(--gutter) clamp(28px, 5vw, 56px);
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 40px) clamp(32px, 6vw, 96px);
  align-items: start;
}
.hero .wordmark { grid-column: 1 / -1; }
.lead {
  margin: 0;
  font-size: clamp(1.2rem, 1rem + 0.8vw, 1.5rem);
  line-height: 1.45;
  max-width: 34ch;
}
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } }

.wordmark {
  font-family: var(--font-display);
  font-size: clamp(5rem, 2rem + 15vw, 13.5rem);
  line-height: 0.82;
  letter-spacing: -0.045em;
  margin: 0;
  color: var(--ink);
  font-weight: 820;
  font-variation-settings: "wdth" 125;
  font-stretch: 125%;
  animation: morph 2.4s cubic-bezier(.6, 0, .2, 1) 0.15s both;
}
@keyframes morph {
  0%   { font-variation-settings: "wdth" 62;  font-weight: 120; letter-spacing: 0.02em; }
  45%  { font-variation-settings: "wdth" 62;  font-weight: 120; letter-spacing: 0.02em; }
  100% { font-variation-settings: "wdth" 125; font-weight: 820; letter-spacing: -0.045em; }
}
@media (prefers-reduced-motion: reduce) { .wordmark { animation: none; } }

.definition { font-size: 1rem; color: var(--muted); max-width: 46ch; margin: 6px 0 0; padding-left: 18px; border-left: 3px solid var(--mark); }
.definition dt {
  font-family: var(--font-display); font-weight: 700; color: var(--ink);
  font-size: 1.05rem;
}
.definition dt i { font-family: var(--font-body); font-weight: 400; color: var(--muted); }
.definition dd { margin: 2px 0 14px; }

.sections {
  max-width: 72rem; margin: 0 auto;
  padding: clamp(40px, 6vw, 72px) var(--gutter) 88px;
}
.sections > ol { list-style: none; margin: 0; padding: 0; }
.sec {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px clamp(24px, 5vw, 72px);
  padding: 30px 0;
  border-top: 1px solid var(--line);
}
.sec:last-child { border-bottom: 1px solid var(--line); }
@media (max-width: 720px) { .sec { grid-template-columns: 1fr; } }

.sec h2 {
  margin: 0;
  font-size: clamp(1.8rem, 1.2rem + 2.2vw, 2.8rem);
  font-weight: 760;
  font-variation-settings: "wdth" 84;
  font-stretch: 84%;
  letter-spacing: -0.025em;
}
.sec h2 a { color: var(--ink); text-decoration: none; }
.sec h2 a:hover { color: var(--accent); }
.sec p { margin: 4px 0 10px; color: var(--muted); }
.sec ul {
  list-style: none; margin: 0; padding: 0;
  font-family: var(--font-display); font-size: 0.98rem;
  display: flex; flex-wrap: wrap; gap: 4px 20px;
}

/* ---------- Contents page ---------- */

.sitemap h2 { margin-top: 1.6em; }
.sitemap ul { list-style: none; padding-left: 0; }
.sitemap ul ul { padding-left: 1.2em; border-left: 1px solid var(--line); margin: 4px 0 8px 4px; }
.sitemap li { margin: 3px 0; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 0.92rem;
  color: var(--muted);
}
.site-footer .bar {
  max-width: 72rem; margin: 0 auto;
  padding: 28px var(--gutter) 40px;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 32px;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--muted); }

@media print {
  .site-header, .site-footer, .aside, .updir { display: none; }
  .page { display: block; }
  body { background: #fff; color: #000; }
}
