/* ---------------------------------------------------------------------------
   Tokens. Change colours and fonts here; everything below reads from these.
   --------------------------------------------------------------------------- */
:root {
  --bg: #fcfbf8;
  --fg: #1d1c1a;
  --muted: #6b6861;
  --rule: #e5e1d8;
  --accent: #b03d0c;
  --surface: #f4f1ea; /* code blocks, inline code, callouts */
  --band: #f5e6d8; /* header background */
  --band-rule: #e9d3c0;
  --line-hl: #fbe9b5; /* highlighted code lines */

  --syn-comment: #6a6760;
  --syn-keyword: #c11f2b;
  --syn-string: #0a3a78;
  --syn-const: #0550ae;
  --syn-func: #7a3fd6;
  --syn-builtin: #8f3700;
  --syn-tag: #116329;
  --syn-add: #dff3e0;
  --syn-del: #fbe0de;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 44rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --fg: #e7e4de;
    --muted: #9c988f;
    --rule: #2d2c29;
    --accent: #f59a62;
    --surface: #1e1d1b;
    --band: #261c15;
    --band-rule: #3a2a1f;
    --line-hl: #3a3320;

    --syn-comment: #8f8b82;
    --syn-keyword: #ff7b72;
    --syn-string: #a5d6ff;
    --syn-const: #79c0ff;
    --syn-func: #d2a8ff;
    --syn-builtin: #ffa657;
    --syn-tag: #7ee787;
    --syn-add: #1c3323;
    --syn-del: #40201f;
  }
}

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

html {
  font-size: 106.25%; /* 17px */
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 1rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

h1,
h2,
h3,
h4 {
  line-height: 1.25;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

/* ---------------------------------------------------------------------------
   Header and footer
   --------------------------------------------------------------------------- */

/* One centred column; the header band behind it runs edge to edge. */
.site-header,
main,
.site-footer {
  width: min(100% - 2.5rem, var(--measure) - 2.5rem);
  margin-inline: auto;
}

.site-band {
  margin-bottom: 2.5rem;
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--band-rule);
  background: var(--band);
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  padding: 1.15rem 0;
}

.site-title {
  color: var(--fg);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.site-header nav,
.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.15rem;
  font-size: 0.9rem;
}

.site-header nav a,
.site-footer nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-header nav a:hover,
.site-footer nav a:hover,
.site-header nav a[aria-current] {
  color: var(--fg);
}

.site-header nav a[aria-current] {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.45em;
}

.site-footer {
  margin-top: 4rem;
  margin-bottom: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

/* ---------------------------------------------------------------------------
   Post lists (home, category, tag, archive)
   --------------------------------------------------------------------------- */
.intro {
  margin: 0 0 2.5rem;
  font-size: 1.2rem;
  color: var(--muted);
}

.list-title {
  margin: 0 0 2rem;
  font-size: 1.7rem;
}

.list-title-prefix {
  color: var(--muted);
  font-weight: 400;
}

.year {
  margin-bottom: 2.25rem;
}

.year h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.post-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.post-list li {
  display: grid;
  grid-template-columns: 4rem 1fr auto;
  align-items: baseline;
  gap: 0 1rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--rule);
}

.post-list time {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.entry-title {
  color: var(--fg);
  font-weight: 550;
  text-decoration: none;
}

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

.entry-domain {
  margin-left: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

.entry-domain::before {
  content: "↗ ";
}

.entry-summary {
  margin: 0.1rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.kind {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-decoration: none;
}

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

.kind.draft {
  color: var(--accent);
}

.pagination {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  font-size: 0.9rem;
}

.page-count {
  color: var(--muted);
}

.tag-cloud,
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tag-cloud li,
.tags a {
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 0.85rem;
}

.tag-cloud a,
.tags a {
  color: var(--fg);
  text-decoration: none;
}

.tag-cloud a:hover,
.tags a:hover {
  color: var(--accent);
}

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

.count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Posts and pages
   --------------------------------------------------------------------------- */
.post-header {
  margin-bottom: 2rem;
}

.post-header h1 {
  margin: 0;
  font-size: clamp(1.7rem, 1.2rem + 2.2vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.9rem;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.post-link {
  margin: 0.75rem 0 0;
  font-weight: 550;
  overflow-wrap: anywhere;
}

.post-footer {
  margin-top: 3rem;
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
}

.post-nav a {
  color: var(--fg);
  text-decoration: none;
}

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

.post-nav a span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.post-nav a[rel="next"] {
  grid-column: 2;
  text-align: right;
}

/* ---------------------------------------------------------------------------
   Prose: everything written in Markdown
   --------------------------------------------------------------------------- */
.prose {
  overflow-wrap: break-word;
}

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

.prose p,
.prose ul,
.prose ol,
.prose dl,
.prose blockquote,
.prose table,
.prose figure {
  margin: 0 0 1.15rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  margin: 2.25rem 0 0.75rem;
}

.prose h1 {
  font-size: 1.5rem;
}

.prose h2 {
  font-size: 1.3rem;
}

.prose h3 {
  font-size: 1.1rem;
}

.prose h4 {
  font-size: 1rem;
}

/* The "#" anchor next to each heading shows on hover. */
.prose .headerlink {
  margin-left: 0.35em;
  color: var(--muted);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
}

.prose :is(h1, h2, h3, h4):hover .headerlink,
.prose .headerlink:focus-visible {
  opacity: 1;
}

.prose ul,
.prose ol {
  padding-left: 1.4rem;
}

.prose li {
  margin: 0.3rem 0;
}

.prose li > ul,
.prose li > ol {
  margin: 0.3rem 0;
}

.prose li::marker {
  color: var(--muted);
}

.prose .task-list-item {
  list-style: none;
  margin-left: -1.4rem;
}

.prose .task-list-item input {
  margin-right: 0.5rem;
}

.prose blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose hr {
  margin: 2.5rem 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

.prose img,
.prose video,
.prose iframe {
  max-width: 100%;
  border-radius: 6px;
}

.prose img,
.prose video {
  height: auto;
}

/* Figures: media with a caption that reads as a caption, not as body text. */
.prose figure {
  margin: 1.9rem 0;
}

.prose figure > img,
.prose figure > video {
  display: block;
}

.prose figcaption {
  margin-top: 0.6rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.prose iframe {
  border: 0;
}

.prose iframe[src*="youtube"] {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}

.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  padding: 0.45rem 0.9rem 0.45rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.prose th {
  border-bottom-color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.prose .footnote {
  margin-top: 2.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Code
   --------------------------------------------------------------------------- */
code,
pre,
kbd {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

.prose :not(pre) > code,
.prose kbd {
  padding: 0.12em 0.35em;
  border-radius: 4px;
  background: var(--surface);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

.prose pre {
  margin: 0 0 1.15rem;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.82rem;
  line-height: 1.6;
  tab-size: 4;
}

/* Highlighted blocks: a frame with a language/title bar and a copy button. */
.prose .highlight {
  position: relative;
  margin: 0 0 1.15rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface);
}

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

.prose .highlight .filename {
  display: block;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.prose .highlight .copy {
  position: absolute;
  top: 0.3rem;
  right: 0.35rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--surface);
  color: var(--muted);
  font: 500 0.72rem var(--font-sans);
  cursor: pointer;
}

.prose .highlight .copy:hover {
  border-color: var(--rule);
  color: var(--fg);
}

/* Lines marked with hl_lines="..." run the full width of the block, however
   far it scrolls sideways. */
.highlight pre > code {
  display: inline-block;
  min-width: 100%;
}

.highlight .hll {
  display: block;
  margin: 0 -1rem;
  padding: 0 1rem;
  background: var(--line-hl);
}

/* Line numbers, from linenums="1" */
.highlight .linenos {
  display: inline-block;
  min-width: 2ch;
  margin-right: 1rem;
  text-align: right;
  color: var(--muted);
  user-select: none;
}

.highlight [data-linenos]::before {
  content: attr(data-linenos);
}

/* Syntax colours (Pygments token classes) */
.highlight :is(.c, .ch, .cm, .c1, .cs, .cp, .cpf) {
  color: var(--syn-comment);
  font-style: italic;
}

.highlight :is(.k, .kc, .kd, .kn, .kp, .kr, .kt, .ow) {
  color: var(--syn-keyword);
}

.highlight :is(.s, .sa, .sb, .sc, .dl, .sd, .s2, .sh, .sx, .sr, .s1, .ss) {
  color: var(--syn-string);
}

.highlight :is(.m, .mb, .mf, .mh, .mi, .mo, .il, .se, .si, .na, .no, .l) {
  color: var(--syn-const);
}

.highlight :is(.nf, .fm, .nc, .nd, .nl) {
  color: var(--syn-func);
}

.highlight :is(.nb, .bp, .ne, .nv, .vc, .vg, .vi, .vm) {
  color: var(--syn-builtin);
}

.highlight .nt {
  color: var(--syn-tag);
}

.highlight :is(.gp, .go) {
  color: var(--syn-comment);
}

.highlight .gp {
  user-select: none;
}

.highlight :is(.gh, .gu, .gs) {
  font-weight: 600;
}

.highlight .ge {
  font-style: italic;
}

.highlight .gi {
  background: var(--syn-add);
}

.highlight .gd {
  background: var(--syn-del);
}

/* ---------------------------------------------------------------------------
   Pasted AI conversation transcripts (output of /extra/aiconvo.html)
   --------------------------------------------------------------------------- */
.ai-conversation {
  margin: 0 0 1.15rem;
  font-size: 0.85rem;
  line-height: 1.55;
}

.ai-conversation .message {
  max-height: 26rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  overflow: auto;
  overflow-wrap: anywhere;
  border-left: 3px solid var(--muted);
  border-radius: 0 6px 6px 0;
  background: var(--surface);
}

.ai-conversation .user {
  border-left-color: var(--syn-const);
}

.ai-conversation .assistant {
  border-left-color: var(--syn-tag);
}

.ai-conversation .system {
  border-left-color: var(--syn-builtin);
  font-style: italic;
}

.ai-conversation .role {
  margin-bottom: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.ai-conversation .metadata {
  margin: -0.25rem 0 1.25rem;
  padding-left: 1rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Small screens
   --------------------------------------------------------------------------- */
@media (max-width: 34rem) {
  .site-band {
    margin-bottom: 2rem;
  }

  .post-list li {
    grid-template-columns: 3.6rem 1fr;
  }

  .post-list .kind {
    display: none;
  }

  .post-nav {
    grid-template-columns: 1fr;
  }

  .post-nav a[rel="next"] {
    grid-column: 1;
    text-align: left;
  }
}
