/* ==========================================================================
   Retro "old-web" theme, in the spirit of the OpenBSD fan sites
   (dataswamp.org & co.), turned towards GNU/Linux.

   One committed look: warm paper, black serif body, monospace chrome,
   classic blue/purple links. No dark mode. The only JavaScript is MathJax on
   posts that ask for it and the click-to-enlarge overlay (theme/js/lightbox.js),
   both of which the page works without.
   ========================================================================== */

:root {
  color-scheme: light;

  --font-mono: ui-monospace, "DejaVu Sans Mono", "Liberation Mono", Menlo,
    Consolas, monospace;
  --font-body: Georgia, "Times New Roman", Times, serif;

  /* Warm paper palette */
  --bg: #f6f2e9;        /* the sheet */
  --bg-page: #e6e0d1;   /* behind the sheet */
  --bg-inset: #ece6d7;  /* code blocks, panels */
  --text: #1c1b17;
  --text-muted: #5b5648;
  --border: #b1a88f;
  --rule: #c9bfa6;
  --link: #1a1ae0;
  --link-visited: #6a1a9c;
  --accent: #8a2b06;    /* rust: heading markers, list bullets */
  --mark: #f6e7a8;      /* link hover highlight */

  --measure: 60rem;

  /* Default display width for a content image. The measure is wide enough
     that an unconstrained screenshot or plot swamps the text around it, so
     images are capped well below it unless a post opts out (.w-wide,
     .w-full). See "Content figures" below. */
  --figure-width: 30rem;
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  background: var(--bg-page);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  max-width: var(--measure);
  margin: 0 auto;
  min-height: 100vh;
  padding: 1.75rem 1.75rem 2.5rem;
  background: var(--bg);
  border-inline: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.075rem;
  line-height: 1.55;
}

/* Links: classic, underlined, with a highlighter hover. */

a {
  color: var(--link);
  text-decoration: underline;
}

a:visited {
  color: var(--link-visited);
}

a:hover,
a:focus {
  background: var(--mark);
  text-decoration: none;
}

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

p,
ul,
ol,
pre,
table,
blockquote,
figure {
  margin: 0 0 1rem;
}

ul,
ol {
  padding-left: 1.5rem;
}

li {
  margin: 0.15rem 0;
}

ul > li::marker {
  color: var(--accent);
}

img,
video {
  max-width: 100%;
  height: auto;
}

hr {
  border: 0;
  border-top: 1px dashed var(--border);
  margin: 1.5rem 0;
}

small {
  font-size: 0.85em;
  color: var(--text-muted);
}

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

blockquote {
  padding-left: 1rem;
  border-left: 3px double var(--border);
  color: var(--text-muted);
}

sup,
sub {
  line-height: 0;
}

/* ==========================================================================
   Headings — monospace, lowercased, with a markdown-style `#` marker
   ========================================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1.25;
  margin: 1.6rem 0 0.7rem;
}

/* Section headings start below any floated media (e.g. the portrait). */
main h1,
main h2 {
  clear: both;
}

main h1 {
  font-size: 1.5rem;
}
main h2 {
  font-size: 1.25rem;
  margin-top: 2rem;
}
main h3 {
  font-size: 1.08rem;
}

main :is(h1, h2, h3)::before {
  color: var(--accent);
  font-weight: 700;
}
main h1::before {
  content: "# ";
}
main h2::before {
  content: "## ";
}
main h3::before {
  content: "### ";
}

/* ==========================================================================
   Skip link
   ========================================================================== */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
  z-index: 10;
  padding: 0.25rem 0.75rem;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  text-decoration: none;
}

/* ==========================================================================
   Header: ASCII banner + bracket nav
   ========================================================================== */

.banner {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}

.banner__id {
  min-width: 12rem;
}

.banner__name {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.banner__name:visited {
  color: var(--text);
}

.banner__name:hover {
  background: var(--mark);
}

.banner__tag {
  margin: 0.15rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.nav {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.9;
  word-spacing: 0.1em;
  color: var(--text-muted);
}

.nav__link {
  color: var(--link);
}

.nav__link.is-current {
  color: var(--accent);
  font-weight: 700;
  background: none;
}

/* ==========================================================================
   Main content
   ========================================================================== */

.main {
  margin: 0;
}

.prose > :first-child {
  margin-top: 0;
}

/* Home hero (blog/tag/category listing headers reuse this) */

.hero {
  margin-bottom: 1rem;
}

.hero__tagline {
  color: var(--text-muted);
  font-style: italic;
}

/* Home project list */

.projects {
  list-style: none;
  padding: 0;
  counter-reset: proj;
}

.projects > li {
  counter-increment: proj;
  position: relative;
  padding-left: 2.8rem;
  margin: 1.1rem 0;
}

.projects > li::before {
  content: "[" counter(proj) "]";
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}

/* Floated portrait (home status section) */

.portrait {
  float: right;
  width: 160px;
  max-width: 40%;
  margin: 0.3rem 0 0.8rem 1.2rem;
  border: 1px solid var(--border);
  padding: 3px;
  background: #fff;
  filter: grayscale(1);
}

.thumb {
  display: block;
  width: 260px;
  max-width: 100%;
  margin: 0.5rem 0 0;
  border: 1px solid var(--border);
  padding: 3px;
  background: #fff;
}

/* Recent-posts block on the front page: a compact changelog. */

.minilog {
  list-style: none;
  padding: 0;
  font-size: 0.98rem;
}

.minilog > li {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  margin: 0.35rem 0;
}

.minilog time {
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

@media (max-width: 34rem) {
  .minilog > li {
    display: block;
  }
}

/* ==========================================================================
   Blog listing & articles
   ========================================================================== */

/* Facet navigation above a listing. Borrows the bracketed monospace idiom
   of the main nav so it reads as chrome rather than content. */

.filter {
  margin: 1.2rem 0 0;
  padding: 0.5rem 0;
  border-block: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.9;
}

.filter__row {
  margin: 0;
  color: var(--text-muted);
}

.filter__label {
  display: inline-block;
  min-width: 5.5rem;
  color: var(--text-muted);
}

.filter__link.is-current {
  color: var(--accent);
  font-weight: bold;
  text-decoration: none;
}

.filter__count {
  color: var(--text-muted);
}

@media (max-width: 34rem) {
  .filter__label {
    display: block;
    min-width: 0;
  }
}

.posts {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
}

.post-item {
  margin: 0 0 1.4rem;
}

/* Posts with an `Image:` put a small fixed-size thumbnail beside the text
   instead of letting a full-width picture push the listing apart. */
.post-item--illustrated {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
}

.post-item__body {
  min-width: 0;
}

.post-item__thumb {
  flex: none;
  display: block;
  width: 7.5rem;
  text-decoration: none;
}

.post-item__thumb:hover,
.post-item__thumb:focus {
  background: none;
}

.post-item__thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.post-item__title {
  margin: 0;
  font-size: 1.1rem;
}

.post-item__title a {
  color: var(--link);
}

.post-item__summary {
  margin: 0.2rem 0;
}

@media (max-width: 34rem) {
  .post-item__thumb {
    width: 5rem;
  }
}

/* Framed content images: a border and a hard offset shadow, no matte, so
   transparent PNGs sit directly on the paper background. The floated
   portrait keeps its own slimmer frame. */
.post-item__thumb img,
.prose img:not(.portrait),
figure img,
figure video {
  border: 1px solid var(--border);
  padding: 4px;
  box-shadow: 3px 3px 0 var(--rule);
}

/* Content figures ----------------------------------------------------------

   Every image in a post is capped at --figure-width and centred, so a plot
   exported at 1024px does not run the full 60rem measure. Width is set by
   one of the .w-* classes, which work on either the <figure> or the <img>
   (custom properties inherit, so the figure's value reaches its image):

       ![alt]({attach}plot.png){: .w-narrow }

       <figure class="w-full" markdown="1">
       ![alt]({attach}plot.png)
       <figcaption markdown="span">Caption with *markup* and [links](/x).</figcaption>
       </figure>

   Wrap a series of related figures in <div class="figure-grid" markdown="1">
   to lay them out side by side instead of stacked; add grid-narrow to that
   div to cap the pair at a narrower width. For media of very different
   shapes, --figure-columns and --grid-width can be set inline so the columns
   follow the media's proportions and the row lines up on a common height:

       <div class="figure-grid" markdown="1"
            style="--figure-columns: 2.5fr 1fr; --grid-width: 44rem">

   To caption the group as a whole, use a <figure class="figure-grid"> as the
   wrapper instead of a <div> and end it with a <figcaption>. */

.w-narrow {
  --figure-width: 18rem;
}

.w-wide {
  --figure-width: 44rem;
}

.w-full {
  --figure-width: 100%;
}

.prose img:not(.portrait) {
  display: block;
  max-width: min(100%, var(--figure-width));
  margin-inline: auto;
}

figure {
  max-width: var(--figure-width);
  margin-inline: auto;
}

/* Markdown-in-HTML wraps the image inside the figure in a paragraph. */
figure > p {
  margin: 0;
}

figcaption {
  margin-top: 0.4rem;
}

/* Inside a grid the column is the constraint, so figures fill it. Setting
   the width here rather than on the children keeps a .w-* class on an
   individual figure working. */
.figure-grid {
  --figure-width: 100%;
  display: grid;
  grid-template-columns: var(--figure-columns, repeat(auto-fit, minmax(22rem, 1fr)));
  max-width: var(--grid-width, none);
  gap: 1.25rem;
  margin: 0 auto 1rem;
}

.figure-grid figure {
  margin: 0;
}

/* A caption for the group as a whole: make the wrapper itself a <figure> and
   end it with a <figcaption>, which then spans the full row under the
   columns. Per-figure captions still work alongside it. */
.figure-grid > figcaption {
  grid-column: 1 / -1;
}

/* A group caption is also valid as the figure's first child, where it reads
   as a heading for the row rather than a note under it. */
.figure-grid > figcaption:first-child {
  margin-top: 0;
}

/* Fill the column instead of stopping at the file's intrinsic width, so a
   small source (a screen-resolution GIF beside a camera JPEG) still matches
   its neighbours. */
.figure-grid img,
.figure-grid video {
  width: 100%;
}

/* A pair of portrait shots does not need the full measure: .grid-narrow caps
   the grid as a whole and pins it to two columns inside that cap. */
.figure-grid.grid-narrow {
  --grid-width: 34rem;
  --figure-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 34rem) {
  .figure-grid {
    grid-template-columns: 1fr;
  }
}

/* Click-to-enlarge overlay -------------------------------------------------

   theme/js/lightbox.js marks every content image .is-zoomable and appends one
   <dialog> to the page; nothing here applies until that script has run. */

.prose img.is-zoomable {
  cursor: zoom-in;
}

.lightbox {
  max-width: 100vw;
  max-height: 100vh;
  width: max-content;
  padding: 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  box-shadow: 6px 6px 0 var(--rule);
  cursor: zoom-out;
}

/* Sized against the viewport rather than the measure: enlarging is the whole
   point, so --figure-width does not apply here. */
.lightbox img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 3rem);
  max-height: calc(100vh - 5.5rem);
  margin-inline: auto;
}

.lightbox__caption {
  max-width: 44rem;
  margin: 0.6rem auto 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.lightbox::backdrop {
  background: rgb(0 0 0 / 0.72);
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.post-meta a {
  color: var(--text-muted);
}

.post-meta__sep::before {
  content: " · ";
  white-space: pre;
}

.article__header {
  margin-bottom: 1.2rem;
}

.article__title {
  margin-top: 0;
}

.article__footer {
  margin-top: 1.6rem;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* Tag index: one tag per row, counts aligned in a column so the list reads
   as an index rather than a paragraph of links. */

.taglist {
  list-style: none;
  padding: 0;
  margin: 1.2rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.taglist__item {
  display: flex;
  gap: 0.8rem;
  align-items: baseline;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--rule);
}

.taglist__item .tag {
  flex: none;
  min-width: 11rem;
  font-size: inherit;
}

.taglist__count {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* Publication lists (academic page) */

.page-academic h2 + ul {
  list-style: none;
  padding-left: 0;
}

.page-academic h2 + ul > li {
  margin: 0 0 0.9rem;
  padding-left: 1.2rem;
  text-indent: -1.2rem;
}

.page-academic h2 + ul > li::before {
  content: "- ";
  font-family: var(--font-mono);
  color: var(--accent);
}

/* ==========================================================================
   Code
   ========================================================================== */

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

:not(pre) > code {
  background: var(--bg-inset);
  padding: 0.05em 0.3em;
  border: 1px solid var(--border);
}

pre {
  overflow-x: auto;
  padding: 0.8rem 1rem;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  line-height: 1.45;
}

.highlight {
  margin: 0 0 1rem;
}

.highlight pre {
  margin: 0;
}

figcaption {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  margin-top: 2rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

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

.foot__meta {
  margin: 0.3rem 0;
  word-spacing: 0.1em;
}

.foot__copy {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
}

/* Old-school 88x31 buttons */

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0.8rem 0;
}

.badge {
  display: grid;
  place-items: center;
  width: 88px;
  height: 31px;
  padding: 0 2px;
  border: 1px solid var(--text);
  border-left: 5px solid var(--accent);
  background: var(--bg-inset);
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.15;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text);
}

.badge b {
  color: var(--accent);
}

/* ==========================================================================
   Narrow screens
   ========================================================================== */

@media (max-width: 34rem) {
  body {
    font-size: 1.02rem;
    padding: 1.25rem 1.1rem 2rem;
  }

  .banner {
    gap: 0.75rem;
  }
}
