/* danbillings.com
   The page is set like a mathematics monograph: a yellow series cover, then
   plain text pages where each library is a theorem-style environment.
   One bold thing (the cover); everything after it stays quiet. */

:root {
  --paper: #fdfcf9;
  --ink: #1b1a17;
  --ink-soft: #55524b;
  --rule: #d9d5cc;
  --cover: #f3c316;
  --cover-ink: #1b1a17;
  --link: #1e4b9c;
  --code-bg: #f2f0ea;

  --serif: "STIX Two Text", "STIX Two", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --measure: 36rem;
  --wide: 66rem;
  --gutter: clamp(16px, 4vw, 40px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17181b;
    --ink: #e8e5de;
    --ink-soft: #a7a39a;
    --rule: #3a3b3f;
    --cover: #e2b40f;
    --cover-ink: #17181b;
    --link: #9cb8ff;
    --code-bg: #212226;
  }
}
:root[data-theme="dark"] {
  --paper: #17181b;
  --ink: #e8e5de;
  --ink-soft: #a7a39a;
  --rule: #3a3b3f;
  --cover: #e2b40f;
  --cover-ink: #17181b;
  --link: #9cb8ff;
  --code-bg: #212226;
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
}

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

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

/* ---------- Masthead ---------- */
.masthead {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 1rem; flex-wrap: wrap;
  padding-top: 1.1rem; padding-bottom: 1.1rem;
}
.masthead a.name {
  color: inherit; text-decoration: none;
  font-variant-caps: all-small-caps; letter-spacing: 0.08em; font-size: 1.15rem;
}
.masthead nav { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 1rem; }
.masthead nav a { color: inherit; }
.theme-toggle {
  font: inherit; font-size: 1rem; color: inherit; background: none; border: 0;
  padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}

/* ---------- Cover ---------- */
.cover {
  background: var(--cover);
  color: var(--cover-ink);
  margin: 0 auto;
  max-width: var(--wide);
}
.cover-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "series vol"
    "title  title"
    "fig    fig"
    "author author";
  row-gap: clamp(1.5rem, 4vw, 2.75rem);
  padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1.25rem, 5vw, 3.5rem) clamp(1.5rem, 4vw, 2.75rem);
}
.series { grid-area: series; font-size: 1rem; font-style: italic; align-self: start; }
.vol {
  grid-area: vol; text-align: right; line-height: 0.85;
  font-size: clamp(2.75rem, 8vw, 4.5rem); font-weight: 700;
  font-variant-numeric: lining-nums;
}
.vol small { display: block; font-size: 0.875rem; font-weight: 400; font-style: italic; line-height: 1.3; }
.cover h1 {
  grid-area: title; margin: 0;
  font-size: clamp(2.6rem, 9vw, 6.25rem);
  line-height: 0.98; font-weight: 700; letter-spacing: -0.015em;
  max-width: 11ch;
  text-wrap: balance;
}
.cover h1 + p {
  margin: 0;
}
.cover figure { grid-area: fig; margin: 0; }
.cover svg { width: 100%; max-width: 34rem; height: auto; display: block; }
.cover figcaption { font-size: 0.95rem; font-style: italic; margin-top: 0.4rem; max-width: 34rem; }
.author {
  grid-area: author;
  border-top: 2px solid currentColor; padding-top: 0.9rem;
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5rem 2rem;
}
.author strong {
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-variant-caps: all-small-caps; letter-spacing: 0.06em; font-weight: 600;
}
.author span { font-size: 1rem; max-width: 30rem; }

/* ---------- Text pages ---------- */
main section { padding-top: clamp(2.5rem, 7vw, 5rem); }
main h2 {
  font-size: clamp(1.75rem, 4vw, 2.4rem); font-weight: 400; font-style: italic;
  line-height: 1.15; margin: 0 0 1.25rem;
}
.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1em; }
.lede { font-size: 1.3rem; line-height: 1.5; }

/* ---------- Libraries: theorem-style environments ---------- */
.envs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr));
  gap: clamp(2rem, 5vw, 3.5rem) clamp(2rem, 5vw, 4rem);
  margin-top: 2rem;
}
.env { border-top: 1px solid var(--rule); padding-top: 1rem; min-width: 0; }
.env h3 { margin: 0 0 0.5rem; font-size: 1.2rem; line-height: 1.35; font-weight: 400; }
.env h3 b { font-weight: 700; }
.env h3 i { font-style: italic; }
.env > p { margin: 0 0 0.85rem; }
.env .how { color: var(--ink-soft); font-size: 1rem; font-style: italic; }
.env-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; font-size: 1rem; margin-top: 0.85rem; }

pre, code { font-family: var(--mono); }
code { font-size: 0.86em; }
pre {
  background: var(--code-bg);
  font-size: 0.8125rem; line-height: 1.55;
  padding: 0.9rem 1rem; margin: 0 0 0.85rem;
  overflow-x: auto; tab-size: 2;
}
pre code { font-size: inherit; }

.coord {
  display: flex; align-items: stretch; gap: 0; margin: 0;
  border: 1px solid var(--rule);
}
.coord code {
  flex: 1; min-width: 0; padding: 0.45rem 0.7rem; font-size: 0.78rem;
  white-space: nowrap; overflow-x: auto;
}
.coord button {
  font: inherit; font-size: 0.9rem; font-style: italic; color: inherit;
  background: none; border: 0; border-left: 1px solid var(--rule);
  padding: 0 0.8rem; cursor: pointer;
}
.coord button:hover { background: var(--code-bg); }

/* ---------- The pattern ---------- */
.pattern { display: grid; grid-template-columns: minmax(0, 24rem) minmax(0, 1fr); gap: 2.5rem; align-items: start; }
@media (max-width: 860px) { .pattern { grid-template-columns: minmax(0, 1fr); } }
.pattern pre { margin-top: 0.25rem; }

/* ---------- Writing ---------- */
.posts { list-style: none; padding: 0; margin: 0; max-width: var(--measure); }
.posts li { padding: 0.75rem 0; border-top: 1px solid var(--rule); }
.posts a { font-size: 1.2rem; }
.posts p { margin: 0.2rem 0 0; color: var(--ink-soft); font-size: 1rem; }

/* ---------- Footer ---------- */
footer.site {
  margin-top: clamp(3.5rem, 9vw, 6rem);
  padding-top: 1.25rem; padding-bottom: 2.5rem;
  border-top: 2px solid var(--ink);
  font-size: 1rem;
}
footer.site .links { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.disclosure {
  max-width: var(--measure);
  margin: 1.5rem 0 0; padding-top: 0.9rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem; font-style: italic; color: var(--ink-soft);
}

/* ---------- Article ---------- */
article.post { max-width: var(--measure); padding-top: clamp(2rem, 6vw, 4rem); }
article.post h1 { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.08; margin: 0 0 0.5rem; text-wrap: balance; }
article.post .date { color: var(--ink-soft); font-style: italic; margin: 0 0 2rem; font-size: 1rem; }
article.post h2 { font-size: 1.5rem; margin: 2.25rem 0 0.75rem; }
article.post p, article.post ul { margin: 0 0 1em; }
article.post pre { margin: 0 0 1.25rem; }

@media (prefers-reduced-motion: no-preference) {
  .cover svg .arrow { stroke-dasharray: 400; stroke-dashoffset: 400; animation: draw 1.1s 0.25s ease-out forwards; }
  .cover svg .head { opacity: 0; animation: show 0.3s 1.2s forwards; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  @keyframes show { to { opacity: 1; } }
}

/* ---------- Long-form posts (tables, figures, quotes) ---------- */
article.post h3 { font-size: 1.2rem; margin: 1.75rem 0 0.5rem; }
article.post img { max-width: 100%; height: auto; display: block; margin: 1rem 0; }
article.post blockquote {
  margin: 0 0 1em; padding-left: 1rem; border-left: 2px solid var(--rule); color: var(--ink-soft);
}
article.post table {
  display: block; overflow-x: auto; max-width: 100%;
  border-collapse: collapse; margin: 0 0 1.25rem;
  font-size: 0.9rem; font-variant-numeric: lining-nums tabular-nums;
}
article.post th, article.post td { padding: 0.35rem 0.75rem 0.35rem 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
article.post th { font-weight: 600; border-bottom-color: var(--ink); }
article.post li { margin-bottom: 0.25rem; }
article.post hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }
