/*
 * Avocet — one stylesheet for a minimalist Pelican theme.
 *
 * No preprocessor and no build step: the browser loads this file as written.
 * Order: fonts, tokens, baseline, skip link, sidebar, main, footer, desktop,
 * pygments, utilities, preferences and print.
 */

/* --------------------------------------------------------------- fonts -- */

/*
 * Variable fonts: one file covers the whole weight range, and font-display:
 * swap keeps text readable while it loads.
 */

@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/source-sans-3-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Source Sans 3";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/source-sans-3-italic.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-normal.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: italic;
  font-weight: 100 800;
  font-display: swap;
  src: url("../fonts/jetbrains-mono-italic.woff2") format("woff2");
}

/* ---------------------------------------------------------------- tokens -- */

/*
 * Every colour and size is named once here, so changing --accent changes every
 * link, button and tag. Light only: one value per token.
 */

:root {
  /* Scrollbars and form controls render light, matching the page. */
  color-scheme: light;

  /* Links and headlines; hover still clears 4.5:1 on white. */
  --accent: #c62828;
  --accent-hover: #d23c3c; /* 4.72:1 on white */

  /* The page and the grey surface behind code. */
  --bg: #ffffff;
  --bg-soft: #f7f7f9;
  --bg-code: #f7f7f9;

  /* Text: body, secondary (dates, captions), and headings. */
  --text: #242121;
  --text-muted: #6b6663;
  --text-heading: #242121;

  /* Rules and table borders, plus the thick edge on quotes and code. */
  --border: #dddddd;
  --border-soft: rgba(128, 128, 128, 0.25);

  /* The dark column keeps its own fixed colours. */
  --sidebar-bg: #333333;
  --sidebar-text: #ffffff;
  --sidebar-muted: rgba(255, 255, 255, 0.6);
  --sidebar-hover: #ff7b7b; /* 5.04:1 on the rail */

  /* Tags and buttons: white text, so hover darkens. */
  --chip-bg: #c62828;
  --chip-text: #ffffff;
  --chip-hover: #a51c1c;

  /* Colours follow the accent: a warm ramp for literals, one cool hue for names,
     one violet for built-ins. Each clears 4.5:1 on --bg-code. */
  --hl-comment: #6e635f;
  --hl-keyword: #c62828;
  --hl-string: #8a5510;
  --hl-number: #86690c;
  --hl-name: #14666f;
  --hl-builtin: #7b4b99;
  --hl-deleted: #c62828;
  --hl-inserted: #4f6b1f;

  /* Bundled font first, then system fonts that look close. */
  --font-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  /* clamp() grows with the viewport but stays inside the bounds. */
  --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.05rem);
  --step-1: 1.28rem;
  --step-2: clamp(1.5rem, 1.35rem + 0.6vw, 1.8rem);
  --step-3: clamp(1.9rem, 1.6rem + 1.2vw, 2.4rem);

  /* Sidebar and content widths. */
  --sidebar-width: clamp(16rem, 23vw, 20rem);
  --sidebar-pad: 2.25rem 1.125rem;
  --content-max: 47.5rem;
  --content-pad: clamp(1rem, 8vw, 4rem);

  --radius: 0.25rem;
}

/* ------------------------------------------------------------- baseline -- */

/* Width and height include padding and border, as layout code expects. */

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

html {
  /* Stops iOS from inflating text when a phone rotates to landscape. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  /* Source Sans 3 is variable, so the body sits between Regular and Light. */
  font-weight: 350;
  font-size: var(--step-0);
  /* Unitless, so it scales with the font size. */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Light (300) and tightly set; text-wrap: balance evens out long headings. */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 1.6em 0 0.5em;
  color: var(--text-heading);
  font-weight: 300;
  line-height: 1.15;
  text-wrap: balance;
}

h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: 1.15em; }
h5 { font-size: 1.05em; }
h6 { font-size: 1em; }

/* Space goes below blocks, so the container controls the top. */
p,
ul,
ol,
dl {
  margin: 0 0 1.2em;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* Underline on hover only, so colour is never the only cue for a state change. */
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* Links in prose keep an underline at rest; colour alone does not identify them. */
.prose a,
.meta a {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* The pilcrow and contents list are navigation, not prose. */
.prose .headerlink,
.prose .toc a {
  text-decoration: none;
}

/* Keyboard focus only, so the ring appears where it helps. */
:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

hr {
  height: 1px;
  margin: 2.5rem 0;
  border: 0;
  background-color: var(--border);
}

/* Never wider than the column, never squashed. */
img {
  max-width: 100%;
  height: auto;
}

table {
  border-collapse: collapse;
  margin-bottom: 1.2em;
}

/* Horizontal rules between rows, and none above the header row. */
th,
td {
  padding: 0.5rem;
  border-top: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

thead th {
  border-top: 0;
}

/* A tint that follows the current text colour instead of a fixed grey. */

blockquote {
  margin: 0 0 1.2em;
  padding: 0.6rem 1.2rem;
  border-left: 10px solid var(--border-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  background-color: color-mix(in srgb, var(--text) 5%, transparent);
  font-size: 1.1em;
  font-weight: 300;
}

/* Thin (100) is the look; raise it if it stops being readable. */
pre,
code,
kbd,
samp {
  font-family: var(--font-mono);
  font-weight: 100;
}

/* A block of code: scrolls sideways instead of widening the page. */
pre {
  overflow-x: auto;
  margin: 1.2em 0;
  padding: 0.75rem 1rem;
  border-left: 10px solid var(--border-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  background-color: var(--bg-code);
  font-size: 0.9em;
  line-height: 1.5;
}

/* Inline chips only; :not(pre) excludes code blocks. */
:not(pre) > code {
  padding: 1px 3px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background-color: var(--bg-soft);
  color: var(--hl-keyword);
  font-size: 0.85em;
  white-space: nowrap;
}

/* Keyboard keys, drawn as a small physical key. */
kbd {
  display: inline-block;
  margin: 0 0.1em;
  padding: 0.1em 0.6em;
  border: 1px solid var(--border);
  border-radius: 3px;
  background-color: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 0 var(--border);
  font-size: 0.78em;
  white-space: nowrap;
}

figure {
  margin: 0 0 1.2em;
  font-size: 90%;
}

figcaption {
  margin-top: 0.5em;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

/* Alignment helpers for images, as produced by Markdown attribute syntax. */
.align-center { margin-inline: auto; display: block; text-align: center; }
.align-left   { display: block; text-align: left; }
.align-right  { display: block; text-align: right; }
.float-left   { float: left; margin-right: 1rem; }
.float-right  { float: right; margin-left: 1rem; }
.text-center  { text-align: center; }

/* ------------------------------------------------------------------ skip -- */

/* Off-screen, not hidden, so it stays in the tab order. */

.skip-link {
  position: absolute;
  left: -9999px;
  z-index: 2000;
  padding: 0.5rem 1rem;
  background-color: var(--accent);
  color: #fff;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
  color: #fff;
}

/* --------------------------------------------------------------- sidebar -- */

/*
 * A block above the content on phones; the desktop query below makes it a
 * column. container-type lets its children query its width.
 */

#sidebar {
  display: block;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  text-align: center;
  container-type: inline-size;
  container-name: sidebar;
}

/* Every link in the sidebar starts white; only the hover changes colour. */
#sidebar a {
  color: var(--sidebar-text);
}

#sidebar a:hover {
  color: var(--sidebar-hover);
  text-decoration: none;
}

/* The red focus ring disappears on the rail, so the sidebar uses white. */
#sidebar :focus-visible {
  outline-color: #ffffff;
}

#sidebar .sidebar-inner {
  padding: var(--sidebar-pad);
}

#sidebar .site-logo {
  display: inline-block;
  max-width: 8.75rem;
  height: auto;
  /* Round avatars: set --logo-radius: 50%. The default keeps artwork that has
     its own shape, like the Avocet mark with its legs below the circle. */
  border-radius: var(--logo-radius, 0);
}

#sidebar .site-title {
  margin: 0.9rem 0 0.3rem;
  font-size: 1.6rem;
  font-weight: 300;
}

#sidebar .site-subtitle {
  margin: 0 0 1rem;
  color: var(--sidebar-muted);
  font-size: 0.92em;
}

/* Menu and social rows are lists; strip bullets and indent once. */
#sidebar nav ul,
#sidebar ul.social {
  margin: 0;
  padding: 0;
  list-style: none;
}

#sidebar nav {
  padding: 0.5rem 0;
}

#sidebar nav a {
  display: block;
  padding: 0.15rem 0;
  font-size: 1.28rem;
  line-height: 1.6;
  text-transform: lowercase;
}

/* Wraps and stays centred. */
#sidebar ul.social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  padding-top: 1.75rem;
}

/* One centred circle per network; --social-bg is set further down. */

#sidebar ul.social a {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background-color: var(--social-bg, rgba(255, 255, 255, 0.12));
  color: var(--social-fg, #fff);
}

/* Darkens instead of lifting: the icon keeps contrast and the row stays put. */
#sidebar ul.social a:hover {
  background-color: color-mix(in srgb, var(--social-bg, rgba(255, 255, 255, 0.12)) 82%, #000);
}

#sidebar .icon {
  width: 1.05rem;
  height: 1.05rem;
}

/* In a narrow column the type steps down instead of wrapping. */

@container sidebar (max-width: 18rem) {
  .site-title {
    font-size: 1.42rem;
  }

  .site-subtitle {
    font-size: 0.84em;
    text-wrap: balance;
  }

  #sidebar nav a {
    font-size: 1.12rem;
  }
}

/* ------------------------------------------------------------------ main -- */

/* Stops a wide element from forcing the column past the screen. */

main {
  min-width: 0;
  padding-block-start: 2.5rem;
}

/* The container supplies the top gap; the first heading must not. */
#content > :first-child h1,
#content > h1 {
  margin-top: 0;
}

/* Side margins from --content-pad; --content-max caps the measure. */

article,
.page-header {
  margin: 0 var(--content-pad) 2rem;
  max-width: var(--content-max);
}

/* Blocks sitting straight under #content need the same inset as articles. */
#content > .tag-cloud,
#content > ul.archive-list,
#content > .neighbors,
#content > .not-found {
  margin-inline: var(--content-pad);
  max-width: var(--content-max);
}

article header h1,
article header h2 {
  margin-bottom: 0.15em;
}

/* The line under a title: date, category, tags. */
.meta {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.86em;
}

.translations {
  float: right;
  font-size: 0.8em;
}

/* Tags: inline blocks so they wrap like words, with a little space between. */
.tag-cloud {
  margin: 2rem 0 0;
}

.tag-cloud a {
  display: inline-block;
  margin: 0 0.15rem 0.3rem 0;
  padding: 0.2em 0.6em;
  border-radius: var(--radius);
  background-color: var(--chip-bg);
  color: var(--chip-text);
  font-size: 0.74em;
  line-height: 1.6;
}

.tag-cloud a:hover {
  background-color: var(--chip-hover);
  color: var(--chip-text);
  text-decoration: none;
}

/* The count sits inside the chip, so it follows the chip text, not the page. */
.tag-cloud .count {
  color: inherit;
  opacity: 0.8;
}

/* Only links, never <button> elements. */
a.btn {
  display: inline-block;
  padding: 0.6em;
  border: 0;
  border-radius: var(--radius);
  background-color: var(--chip-bg);
  color: var(--chip-text);
  font-size: 0.8em;
  line-height: 1;
}

a.btn:hover {
  background-color: var(--chip-hover);
  color: var(--chip-text);
  text-decoration: none;
}

/* Older/newer links: two items at the ends of one row. */
.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 2.5rem var(--content-pad);
}

/* Previous and next article: pushed apart with space-between. */
.neighbors {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  margin: 2.5rem 0;
  font-size: 0.95em;
}

/* The table of contents generated by Markdown's [TOC] marker. */
.toc {
  margin: 2em 0;
  padding: 0.25rem 1rem;
  border-left: 3px solid var(--border);
  font-size: 0.92em;
}

.toc .toctitle {
  margin: 0 0 0.5rem;
  font-size: 1.3em;
  font-weight: 300;
}

.toc ul {
  margin: 0;
  padding-inline-start: 1rem;
  list-style: none;
}

.toc li {
  padding: 0.05rem 0;
}

.toc a {
  color: var(--text);
}

.toc a:hover {
  color: var(--accent);
}

.toc > ul {
  padding-inline-start: 0;
}

/* One entry in the article list on the index and archive pages. */
.listing-item {
  margin-bottom: 2.25rem;
}

.listing-item h2 {
  margin: 0 0 0.25rem;
}

.listing-item .summary {
  margin: 0.5rem 0;
}

.read-more {
  font-size: 0.9em;
}

/* Archive and category lists: no bullets, a little space per line. */
ul.archive-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

ul.archive-list li {
  padding: 0.2rem 0;
}

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

footer.site-footer {
  margin-top: 3rem;
  padding: 1rem var(--content-pad) 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
}

footer.site-footer p {
  margin: 0.25rem 0;
}

/* -------------------------------------------------------------- desktop -- */

/*
 * The only layout breakpoint: sidebar plus a content column. minmax(0, 1fr)
 * lets the text shrink instead of overflowing; the sidebar is sticky, so it
 * stays in view without padding tricks on main.
 */

@media (min-width: 48rem) {
  body {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  #sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100dvh;
    overflow-y: auto;
    text-align: center;
  }
}

/* -------------------------------------------------------------- pygments -- */

/*
 * Pygments marks each token with a class (.k keyword, .s string, .c comment);
 * these rules map them onto the --hl-* tokens. The wrapper carries the spacing,
 * so the inner pre is reset to zero.
 */

.highlight {
  margin: 1.2em 0;
  background-color: var(--bg-code);
  border-radius: var(--radius);
}

.highlight pre {
  margin: 0;
  border-left: 0;
  background: none;
}

/* .hll marks lines a code block was asked to emphasise. */
.highlight .hll { background-color: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Comments. Every Pygments comment class shares one colour and is italic. */
.highlight .c,
.highlight .ch,
.highlight .cm,
.highlight .cp,
.highlight .cpf,
.highlight .c1,
.highlight .cs { color: var(--hl-comment); font-style: italic; }

/* Keywords: if, for, def, return, and operators written as words. */
.highlight .k,
.highlight .kc,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt,
.highlight .ow { color: var(--hl-keyword); }

/* Strings, including docstrings and escaped characters. */
.highlight .s,
.highlight .sa,
.highlight .sb,
.highlight .sc,
.highlight .dl,
.highlight .sd,
.highlight .s2,
.highlight .se,
.highlight .sh,
.highlight .si,
.highlight .sx,
.highlight .sr,
.highlight .s1,
.highlight .ss { color: var(--hl-string); }

/* Numbers and constants. */
.highlight .m,
.highlight .mb,
.highlight .mf,
.highlight .mh,
.highlight .mi,
.highlight .mo { color: var(--hl-number); }

/* Names: functions, classes, modules, variables. */
.highlight .nc,
.highlight .nd,
.highlight .ne,
.highlight .nf,
.highlight .nl,
.highlight .nn,
.highlight .nt,
.highlight .nv,
.highlight .py,
.highlight .vc,
.highlight .vg,
.highlight .vi,
.highlight .vm { color: var(--hl-name); }

/* Built-ins and attributes: things a language provides rather than the author. */
.highlight .na,
.highlight .nb,
.highlight .bp,
.highlight .no { color: var(--hl-builtin); }

.highlight .nf { font-weight: 600; }
.highlight .gd { color: var(--hl-deleted); }
.highlight .gi { color: var(--hl-inserted); }
.highlight .gh,
.highlight .gu,
.highlight .gp { color: var(--text-muted); font-weight: 600; }
.highlight .err { color: var(--hl-deleted); }
/* Whitespace tokens would otherwise show as boxes. */
.highlight .w { color: transparent; }

/* ------------------------------------------------------------ utilities -- */

/* Sized in em, so icons follow the text. */
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
}

/* Present in the page, but takes no space. */
.icon-sprite {
  display: none;
}

/* Off-screen but still announced. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

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

.archive-year {
  margin: 0 var(--content-pad) 2rem;
  max-width: var(--content-max);
}

.archive-year h2 {
  margin-top: 1.5rem;
}

/* One colour per service; read above as --social-bg and --social-fg. */
#sidebar ul.social a { --social-bg: rgba(255, 255, 255, 0.12); --social-fg: #fff; }
#sidebar ul.social a[data-network="github"],
#sidebar ul.social a[data-network="github-alt"] { --social-bg: #181717; }
#sidebar ul.social a[data-network="gitlab"] { --social-bg: #fc6d26; --social-fg: #242121; }
#sidebar ul.social a[data-network="codeberg"] { --social-bg: #2185d0; }
#sidebar ul.social a[data-network="mastodon"] { --social-bg: #6364ff; }
#sidebar ul.social a[data-network="matrix"] { --social-bg: #0dbd8b; --social-fg: #242121; }
#sidebar ul.social a[data-network="reddit"] { --social-bg: #ff4500; }
#sidebar ul.social a[data-network="youtube"] { --social-bg: #ff0000; }
#sidebar ul.social a[data-network="x"],
#sidebar ul.social a[data-network="twitter"] { --social-bg: #000000; }
#sidebar ul.social a[data-network="bluesky"] { --social-bg: #0285ff; }
#sidebar ul.social a[data-network="rss"] { --social-bg: #c62828; }
#sidebar ul.social a[data-network="email"],
#sidebar ul.social a[data-network="mail"],
#sidebar ul.social a[data-network="envelope"],
#sidebar ul.social a[data-network="at"] { --social-bg: #c62828; }

/* Shown when a network has no icon in the sprite: its name, small. */
.social-fallback {
  font-size: 0.75rem;
  line-height: 1;
}

/* The ¶ that Markdown's "permalink" setting puts after each heading. */
.headerlink {
  margin-left: 0.25em;
  color: var(--text-muted);
  font-size: 0.65em;
  text-decoration: none;
}

.headerlink:hover {
  color: var(--accent);
}

/* Honour the reader's request for less motion. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Printing: drop the navigation chrome and force black text on white paper. */
@media print {
  #sidebar,
  footer.site-footer,
  .pagination,
  .neighbors {
    display: none;
  }

  body {
    display: block;
    color: #000;
    background: #fff;
  }
}
