/* ==========================================================================
   Tokens
   Colour is used for marks, not surfaces: each post has a vivid hue (--h, set
   on any element carrying [data-hue]) that colours its dot, link underlines,
   notes and text selection. Text itself stays near-black on paper.
   Neutrals are cool greys; pages that aren't a post use the site's burgundy.
   ========================================================================== */

:root {
  --paper: #fcfcfd;
  --ink: #1c2127;
  --ink-2: #3f4851;
  --muted: #5c6670;
  --rule: #e3e7ea;
  --wash: #f1f3f5;
  --site-accent: #92263e;

  /* Accent lightness/chroma per theme; hue comes from --h. */
  --accent-l: 54%;
  --accent-c: 0.2;
  --h: 25;

  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --measure: 40rem;
  /* Header and footer: as wide as the widest page, so they don't jump between pages. */
  --site-width: var(--measure);
  --gutter: 1.25rem;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14171a;
    --ink: #dde2e7;
    --ink-2: #b6bec6;
    --muted: #97a1ab;
    --rule: #272c31;
    --wash: #1a1e22;
    --site-accent: #e28a9e;
    --accent-l: 76%;
    --accent-c: 0.15;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #14171a;
  --ink: #dde2e7;
  --ink-2: #b6bec6;
  --muted: #97a1ab;
  --rule: #272c31;
  --wash: #1a1e22;
  --site-accent: #e28a9e;
  --accent-l: 76%;
  --accent-c: 0.15;
  color-scheme: dark;
}

/* Recomputed wherever --h changes, so each post item gets its own colour. */
:root,
[data-hue] {
  --accent: oklch(var(--accent-l) var(--accent-c) var(--h));
  --accent-soft: color-mix(in oklch, var(--accent) 45%, transparent);
  --accent-faint: color-mix(in oklch, var(--accent) 12%, transparent);
}

/* Off post pages, the page-level accent (header dot, links) is burgundy;
   post items inside the page still carry their own hues. */
body:not(.post-page) {
  --accent: var(--site-accent);
}

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

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.0625rem, 0.95rem + 0.4vw, 1.1875rem);
  line-height: 1.6;
  font-optical-sizing: auto;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
  padding-inline: var(--gutter);
}

::selection {
  background: var(--accent-soft);
}

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--accent-soft);
  text-decoration-thickness: 0.09em;
  text-underline-offset: 0.18em;
  transition:
    color 0.15s,
    text-decoration-color 0.15s;
}

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

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

/* Author display rules (e.g. grid on list items) would otherwise override it. */
[hidden] {
  display: none !important;
}

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

.meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--muted);
}

/* ==========================================================================
   Status dot: filled = finished, half-filled = unfinished
   ========================================================================== */

.dot {
  display: inline-block;
  flex: none;
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: var(--accent);
  border: 0.09em solid var(--accent);
}

.dot--unfinished {
  background: linear-gradient(90deg, var(--accent) 50%, transparent 50%);
}

.star {
  display: inline-block;
  flex: none;
  width: 0.55em;
  text-align: center;
  line-height: 1;
  color: var(--accent);
}

.dot--inline {
  vertical-align: 0.05em;
  margin-inline: 0.1em;
}

/* ==========================================================================
   Header & footer
   ========================================================================== */

.site-header,
.site-footer {
  max-width: var(--site-width);
  margin-inline: auto;
}

.page {
  max-width: var(--measure);
  margin-inline: auto;
}

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

.site-name {
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
  white-space: nowrap;
}

.site-name:hover {
  color: inherit;
}

.site-name-pre {
  font-weight: 400;
  color: var(--ink-2);
}

.site-nav {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  font-size: 0.95rem;
}

.site-nav a {
  text-decoration: none;
  color: var(--ink-2);
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.theme-toggle {
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--ink-2);
  background: none;
  border: 0;
  padding: 0.15rem;
  cursor: pointer;
  transition: transform 0.4s ease;
}

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

[data-theme="dark"] .theme-toggle {
  transform: rotate(180deg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle {
    transform: rotate(180deg);
  }
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-top: 5rem;
  padding-block: 1.5rem 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.site-footer a {
  text-decoration: none;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
}

/* ==========================================================================
   Page scaffolding
   ========================================================================== */

.page {
  padding-top: 3.5rem;
}

.page-title {
  font-size: 2.1rem;
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
  text-wrap: balance;
}

.lede {
  color: var(--ink-2);
  margin: 0 0 2.5rem;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  margin: 0 0 0.9rem;
}

.section-title::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--rule);
}

.section-note {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--muted);
}

.more-link {
  margin-top: 2.5rem;
}

/* ==========================================================================
   Post lists
   ========================================================================== */

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

.post-item {
  display: grid;
  grid-template-columns: 0.55em 1fr auto;
  column-gap: 0.85rem;
  align-items: baseline;
  padding-block: 0.45rem;
}

.post-item-body {
  grid-column: 2;
}

.post-item-date {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
}

.post-item .dot {
  align-self: baseline;
  transform: translateY(-0.05em);
}

.post-item-title {
  font-weight: 550;
  text-decoration: none;
  text-wrap: pretty;
}

.post-item-title:hover {
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.post-item-desc {
  margin: 0.15rem 0 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-2);
  text-wrap: pretty;
}

.post-item-date {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.post-list--described .post-item {
  padding-block: 0.65rem;
}

.post-list--compact .post-item {
  padding-block: 0.25rem;
  font-size: 0.92rem;
}

.post-item--unfinished .post-item-title {
  font-weight: 450;
  color: var(--ink-2);
}

@media (max-width: 34rem) {
  .post-item {
    grid-template-columns: 0.55em 1fr;
  }

  .post-item-date {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
  }
}

.ext {
  margin-left: 0.3em;
  font-size: 0.75em;
  color: var(--muted);
}

/* ==========================================================================
   Home
   ========================================================================== */

.home-section {
  margin-top: 3rem;
}

.home-section:first-child {
  margin-top: 0;
}

/* Wide screens: Selected moves to a sticky right-hand column. */
@media (min-width: 64rem) {
  :root {
    --site-width: 62rem;
  }

  .home-page {
    --measure: 62rem;
  }

  .home-grid {
    display: grid;
    grid-template-columns: minmax(0, 36rem) minmax(0, 1fr);
    grid-template-areas:
      "latest selected"
      "unfinished selected"
      "more selected";
    grid-template-rows: auto auto 1fr;
    column-gap: 4rem;
  }

  .home-latest {
    grid-area: latest;
  }

  .home-unfinished {
    grid-area: unfinished;
  }

  .home-more {
    grid-area: more;
  }

  .home-selected {
    grid-area: selected;
    align-self: start;
    position: sticky;
    top: 2rem;
    margin-top: 0;
  }

  /* The narrower column puts dates under titles. */
  .home-selected .post-item {
    grid-template-columns: 0.55em 1fr;
  }

  .home-selected .post-item-date {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
  }
}

.home-section--quiet {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--rule);
}

.feature {
  display: grid;
  grid-template-columns: 0.55em 1fr;
  column-gap: 0.85rem;
  align-items: baseline;
  padding-block: 0.3rem 0.9rem;
}

@media (max-width: 34rem) {
  .feature .feature-title {
    font-size: 1.3rem;
  }
}

.feature-title {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.feature-title a {
  text-decoration: none;
}

.feature-title a:hover {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.15em;
}

.feature-desc {
  margin: 0.35rem 0 0;
  color: var(--ink-2);
  text-wrap: pretty;
}

.feature .meta {
  margin: 0.4rem 0 0;
}

/* ==========================================================================
   Writing (archive)
   ========================================================================== */

.year-group {
  display: grid;
  grid-template-columns: 4rem 1fr;
  column-gap: 1rem;
  margin-top: 1.5rem;
}

.year {
  margin: 0;
  padding-top: 0.45rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

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

  .year {
    padding-top: 0;
  }
}

/* Drafts sit among finished posts on the Writing page, in smaller type. */
.writing .post-item--unfinished {
  font-size: 0.88em;
  padding-block: 0.3rem;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  margin: -1rem 0 2rem;
}

.tag-filter button {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

.tag-filter button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.tag-filter button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}

.tag-count {
  margin-left: 0.35em;
  opacity: 0.6;
}

/* ==========================================================================
   Post
   ========================================================================== */

.post-article {
  position: relative;
}

.post-header {
  margin-bottom: 2rem;
}

.post-kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.4rem;
  margin: 0 0 0.9rem;
}

.post-kicker .dot {
  margin-right: 0.2rem;
}

.post-title {
  margin: 0;
  font-size: clamp(2rem, 1.5rem + 2vw, 2.6rem);
  line-height: 1.12;
  font-weight: 650;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.unfinished-note {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  margin: 0 0 2.25rem;
  padding: 0.85rem 1rem;
  border: 1px dashed var(--accent-soft);
  border-radius: 6px;
  background: var(--wash);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.unfinished-note p {
  margin: 0;
}

.unfinished-note strong {
  color: var(--ink);
}

.post-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
  color: var(--ink-2);
}

.post-tags a {
  font-family: var(--mono);
  font-size: 0.85em;
}

.comments-link {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.post-footer p {
  margin: 0 0 0.5rem;
}

/* ==========================================================================
   Prose: post bodies and long-form pages
   ========================================================================== */

.prose {
  hanging-punctuation: first;
}

.prose > * {
  margin-block: 0 1.1em;
}

.prose p,
.prose li {
  text-wrap: pretty;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  line-height: 1.25;
  font-weight: 650;
  text-wrap: balance;
  scroll-margin-top: 1.5rem;
}

.prose h1,
.prose h2 {
  font-size: 1.4em;
  margin: 2.2em 0 0.6em;
  letter-spacing: -0.005em;
}

.prose h3 {
  font-size: 1.15em;
  margin: 1.8em 0 0.5em;
}

.prose h4 {
  font-size: 1em;
  margin: 1.5em 0 0.4em;
}

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

.prose li {
  margin-block: 0.3em;
}

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

.prose ol > li::marker {
  font-variant-numeric: tabular-nums;
}

.prose blockquote {
  margin-inline: 0;
  padding-left: 1.1em;
  border-left: 2px solid var(--accent-soft);
  color: var(--ink-2);
}

/* Section breaks: a centred asterism rather than a line. */
.prose hr:not(.footnotes-sep) {
  border: 0;
  margin: 2.5em 0;
  text-align: center;
  color: var(--accent);
}

.prose hr:not(.footnotes-sep)::after {
  content: "⁂";
  font-size: 1.1em;
}

.prose img,
.prose svg,
.prose video {
  display: block;
  margin-inline: auto;
}

.prose figure {
  margin-inline: 0;
}

.prose figcaption {
  margin-top: 0.5em;
  font-size: 0.85em;
  color: var(--muted);
  text-align: center;
}

.prose audio {
  width: 100%;
  max-width: 24rem;
  height: 2.2rem;
}

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

.prose :not(pre) > code {
  font-size: 0.84em;
  padding: 0.08em 0.3em;
  border-radius: 3px;
  background: var(--wash);
}

.prose pre {
  font-size: 0.78rem;
  line-height: 1.6;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  background: var(--wash);
  border-radius: 6px;
  tab-size: 4;
}

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

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

.prose th {
  font-weight: 600;
  border-bottom-color: var(--ink-2);
}

/* Math */
.katex {
  font-size: 1.08em;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 0.25em;
}

/* Footnotes (bottom), shown on narrow screens or without JS */
.footnote-ref {
  font-size: 0.7em;
  line-height: 0;
}

.footnote-ref a {
  font-family: var(--mono);
  font-weight: 500;
  text-decoration: none;
  color: var(--accent);
  padding-inline: 0.1em;
}

.footnotes-sep {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 3rem 0 1rem;
  width: 6rem;
}

.footnotes {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.footnotes-list {
  padding-left: 1.4em;
}

.footnote-backref {
  text-decoration: none;
  color: var(--accent);
}

/* Fiction: a touch more air. */
.post-article--fiction .prose {
  line-height: 1.7;
}

/* ==========================================================================
   Wide screens: sidenotes in the right margin, contents in the left
   ========================================================================== */

.sidenote,
.toc {
  display: none;
}

@media (min-width: 1240px) {
  .has-sidenotes .footnotes,
  .has-sidenotes .footnotes-sep {
    display: none;
  }

  .sidenote {
    display: block;
    float: right;
    clear: right;
    position: relative;
    width: 13.5rem;
    margin: 0.3rem -16.5rem 0.75rem 0;
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--ink-2);
    text-indent: 0;
  }

  .sidenote p {
    display: inline;
    margin: 0;
  }

  .sidenote p + p::before {
    content: "";
    display: block;
    height: 0.4em;
  }

  .sidenote-num {
    font-family: var(--mono);
    font-weight: 500;
    font-size: 0.85em;
    color: var(--accent);
    margin-right: 0.4em;
  }

  .toc {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    right: calc(100% + 3rem);
    width: 12rem;
  }

  .toc-inner {
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
  }

  .toc-title {
    margin: 0 0 0.5rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--muted);
  }

  .toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .toc li {
    margin-block: 0.45rem;
  }

  .toc .toc-h3 {
    padding-left: 0.8rem;
    font-size: 0.95em;
  }

  .toc a {
    display: block;
    text-decoration: none;
    color: var(--muted);
    border-left: 2px solid transparent;
    padding-left: 0.6rem;
    margin-left: -0.75rem;
  }

  .toc a:hover,
  .toc a.is-current {
    color: var(--ink);
    border-left-color: var(--accent);
  }
}

/* ==========================================================================
   About
   ========================================================================== */

.about-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.about-header .page-title {
  margin-bottom: 0.35rem;
}

.about-header .meta {
  margin: 0;
}

.about-photo {
  flex: none;
  width: 8.5rem;
  height: 8.5rem;
  border-radius: 50%;
  object-fit: cover;
  box-shadow:
    0 0 0 4px var(--paper),
    0 0 0 5px var(--accent-soft);
}

.about-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  list-style: none;
  margin: 2rem 0 0;
  padding: 1.25rem 0 0;
  border-top: 1px solid var(--rule);
}

.about-links li:first-child a {
  font-weight: 600;
}

@media (max-width: 34rem) {
  .about-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==========================================================================
   CV
   ========================================================================== */

.cv-header {
  margin-bottom: 2.5rem;
}

.cv-contact,
.cv-downloads {
  margin: 0.25rem 0;
}

.cv-contact {
  font-size: 0.9rem;
  color: var(--ink-2);
}

.cv-contact a {
  text-decoration: none;
}

.cv-downloads {
  font-weight: 600;
}

.cv-section {
  margin-top: 2.75rem;
}

.cv-section h2 {
  font-size: 1.15rem;
  font-weight: 650;
  margin: 0 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
}

.cv-text {
  margin: 0 0 0.75rem;
  text-wrap: pretty;
}

.cv-entry {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  column-gap: 1.25rem;
  margin-bottom: 1.1rem;
}

.cv-entry.no-date .cv-content {
  grid-column: 1 / -1;
}

.cv-date {
  padding-top: 0.2rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.cv-content .title {
  font-weight: 600;
}

.cv-content .org {
  font-style: italic;
  color: var(--ink-2);
}

.cv-content .details {
  margin-top: 0.25rem;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.cv-content .details ul {
  margin: 0.25rem 0 0;
  padding-left: 1.2em;
}

.pub-entry {
  margin-bottom: 1.1rem;
}

.pub-title {
  font-weight: 600;
}

.pub-authors,
.pub-venue {
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink-2);
}

.pub-venue {
  font-style: italic;
}

.cv-updated {
  margin-top: 3rem;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
