/* ============================================================
   rosscarter.uk — one column, system fonts, light and dark.
   No gradients, no shadows, no hover-lift. Structure comes from
   whitespace, a hairline rule, and one accent colour.
   ============================================================ */

:root {
  color-scheme: light dark;

  --bg:       #fcfcfa;
  --bg-sunk:  #f4f4f0;
  --text:     #17181c;
  --text-dim: #5c5f6b;
  --rule:     #e2e2dc;
  --rule-firm:#c9c9c1;
  --accent:   #2b4fbe;
  --accent-dim: #4664c9;

  --measure:  34rem;   /* prose column */
  --frame:    46rem;   /* page frame: lists and metadata run wider */

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

  --step-0: 1rem;
  --step-1: 1.15rem;
  --step-2: 1.4rem;
  --step-3: clamp(1.6rem, 1.2rem + 1.6vw, 2.1rem);
}

:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --bg:       #101116;
    --bg-sunk:  #171920;
    --text:     #e5e6ea;
    --text-dim: #969aa8;
    --rule:     #262832;
    --rule-firm:#3a3d4a;
    --accent:   #8ba6ff;
    --accent-dim: #7893f0;
  }
}

:root[data-theme="dark"] {
  --bg:       #101116;
  --bg-sunk:  #171920;
  --text:     #e5e6ea;
  --text-dim: #969aa8;
  --rule:     #262832;
  --rule-firm:#3a3d4a;
  --accent:   #8ba6ff;
  --accent-dim: #7893f0;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-dim); }

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

img, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }

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

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 16px;
  background: var(--bg);
  border: 1px solid var(--rule-firm);
  z-index: 20;
}
.skip:focus { left: 16px; top: 12px; }

/* ---------- background canvas (front page only) ---------- */
#bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.32;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, #000 0%, transparent 62%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 62%);
}
.has-canvas > :not(#bg) { position: relative; z-index: 1; }

/* ---------- frame ---------- */
.masthead, main, .footer {
  max-width: var(--frame);
  margin-inline: auto;
  padding-inline: 16px;
}

/* ---------- masthead ---------- */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 20px;
  padding-block: 28px 18px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 52px;
}
.masthead-name {
  font-family: var(--mono);
  font-size: 0.9rem;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}
.masthead-name:hover { color: var(--accent); }
.masthead nav { display: flex; flex-wrap: wrap; gap: 18px; }
.masthead nav a {
  font-size: 0.9rem;
  color: var(--text-dim);
  text-decoration: none;
}
.masthead nav a:hover { color: var(--text); }
.masthead nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

/* ---------- shared headings ---------- */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.kicker {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  margin-bottom: 14px;
}
.kicker a { color: var(--text-dim); }
.kicker a:hover { color: var(--accent); }
.kicker span { margin-inline: 6px; opacity: 0.55; }

.page-head { margin-bottom: 44px; }
.page-head h1, .intro h1 { font-size: var(--step-3); }
.page-standfirst, .post-standfirst {
  max-width: var(--measure);
  margin-top: 14px;
  color: var(--text-dim);
  font-size: var(--step-1);
  line-height: 1.55;
  text-wrap: pretty;
}

/* ---------- front page intro ---------- */
.intro { margin-bottom: 64px; }
.intro-body {
  max-width: var(--measure);
  margin-top: 22px;
  display: grid;
  gap: 16px;
  color: var(--text-dim);
  text-wrap: pretty;
}
.intro-body p { font-size: var(--step-1); line-height: 1.6; }

/* ---------- panels (front-page sections) ---------- */
.panel {
  padding-top: 26px;
  border-top: 1px solid var(--rule);
  margin-bottom: 40px;
}
.panel-title {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 20px;
}
.panel-title a { color: inherit; text-decoration: none; }
.panel-title a:hover { color: var(--accent); }
.panel-more { margin-top: 18px; font-size: 0.9rem; }
.panel-more a { text-decoration: none; }
.panel-more a:hover { text-decoration: underline; }

.prose-p { max-width: var(--measure); color: var(--text-dim); text-wrap: pretty; }

/* ---------- entry lists (posts, projects, links) ---------- */
.entry-list { list-style: none; padding: 0; display: grid; gap: 4px; }
.entry {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 2px 20px;
  align-items: baseline;
  padding-block: 11px;
  border-bottom: 1px solid var(--rule);
}
.entry:last-child { border-bottom: none; }
.entry-wide { grid-template-columns: 1fr auto; }
.entry-date {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.entry-link {
  font-size: var(--step-1);
  color: var(--text);
  text-decoration: none;
  text-wrap: pretty;
}
.entry-link:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.entry-link code { font-size: 0.95em; }
.entry-tag {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.entry-note {
  grid-column: 2;
  color: var(--text-dim);
  font-size: 0.92rem;
  max-width: var(--measure);
  text-wrap: pretty;
}
.entry-wide .entry-note { grid-column: 1 / -1; }

.draft-flag {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--text-dim);
  padding: 1px 6px;
  border-radius: 3px;
  vertical-align: 2px;
}

.empty-note { color: var(--text-dim); }
.empty-note code { background: var(--bg-sunk); padding: 1px 5px; border-radius: 3px; }

/* ---------- archive / section headings ---------- */
.archive-year { margin-bottom: 36px; }
.archive-heading {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-firm);
  margin-bottom: 8px;
}

/* ---------- publications ---------- */
.reflist {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 2px;
  /* An explicit counter: the rows are grid containers, not list-items, so the
     implicit list-item counter never increments. */
  counter-reset: ref;
}
.ref {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 4px 12px;
  align-items: baseline;
  padding-block: 16px;
  border-bottom: 1px solid var(--rule);
  counter-increment: ref;
}
.ref:last-child { border-bottom: none; }
.ref::before {
  content: counter(ref) ".";
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.ref-title { grid-column: 2; }
.ref-title a {
  color: var(--text);
  font-size: var(--step-1);
  font-weight: 500;
  text-decoration: none;
  text-wrap: pretty;
}
.ref-title a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.ref-meta {
  grid-column: 2;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}
.ref-doi { font-family: var(--mono); font-size: 0.8rem; word-break: break-all; }
.ref-meta strong { color: var(--text); font-weight: 600; }
/* Preprints restart their own numbering under a second heading. */
.preprint-section { margin-top: 48px; }
.preprint-section .reflist { counter-reset: ref; }

/* ---------- CV ---------- */
.cv-section { margin-bottom: 44px; }
.cv-list { display: grid; gap: 2px; }
.cv-row {
  display: grid;
  /* Wide enough for "Jul 2023 – Present" on one line. */
  grid-template-columns: 10.5rem 1fr;
  gap: 4px 20px;
  padding-block: 16px;
  border-bottom: 1px solid var(--rule);
}
.cv-row:last-child { border-bottom: none; }
.cv-when {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
}
.cv-what { margin: 0; }
.cv-role { font-size: var(--step-1); font-weight: 600; letter-spacing: -0.01em; }
.cv-org { color: var(--text); font-size: 0.95rem; }
.cv-detail { color: var(--text-dim); font-size: 0.92rem; margin-top: 6px; max-width: var(--measure); text-wrap: pretty; }
.cv-bullets {
  margin-top: 8px;
  padding-left: 1.1em;
  display: grid;
  gap: 5px;
  max-width: var(--measure);
}
.cv-bullets li {
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.5;
  text-wrap: pretty;
}
.cv-bullets::marker, .cv-bullets li::marker { color: var(--rule-firm); }
/* Teaching list is not nested under a role, so it needs its own top margin. */
.cv-bullets-flush { margin-top: 18px; }
.cv-talk { font-size: 0.95rem; color: var(--text); text-wrap: pretty; }
.cv-talk + .cv-detail { margin-top: 3px; }

.skills { display: grid; gap: 26px; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); margin-top: 18px; }
.skill-heading { font-size: 0.95rem; font-weight: 600; margin-bottom: 10px; }
.skill-group ul { list-style: none; padding: 0; display: grid; gap: 5px; }
.skill-group li { color: var(--text-dim); font-size: 0.9rem; line-height: 1.45; }

/* ---------- blog post prose ---------- */
.prose { max-width: var(--measure); }
.post-head { margin-bottom: 38px; }
.post-head h1 { font-size: var(--step-3); }

.prose > * + * { margin-top: 1.1em; }
.prose p { text-wrap: pretty; }
.prose h2 {
  font-size: var(--step-2);
  margin-top: 2.2em;
  padding-top: 0.6em;
  border-top: 1px solid var(--rule);
}
.prose h3 { font-size: var(--step-1); margin-top: 1.9em; }
.prose ul, .prose ol { padding-left: 1.4em; display: grid; gap: 6px; }
.prose li { text-wrap: pretty; }
.prose blockquote {
  border-left: 2px solid var(--rule-firm);
  padding-left: 18px;
  color: var(--text-dim);
}
.prose hr { border: none; border-top: 1px solid var(--rule); margin-block: 2.4em; }
.prose :not(pre) > code {
  background: var(--bg-sunk);
  border: 1px solid var(--rule);
  padding: 1px 5px;
  border-radius: 4px;
}
.prose pre {
  background: var(--bg-sunk);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 16px 18px;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.85rem;
}
.prose pre code { background: none; border: none; padding: 0; }

/* Figures, code, tables and other wide blocks keep the text's left edge but
   run out to the full page frame, so they breathe without breaking alignment. */
.prose figure, .prose img, .prose video { width: 100%; }
.prose figure { margin-block: 2em; }
@media (min-width: 52rem) {
  .prose figure,
  .prose > img,
  .prose > video,
  .prose pre,
  .prose .table-scroll,
  .prose .wide {
    width: min(var(--frame) - 32px, 100vw - 32px);
    max-width: none;
  }
}
.prose img, .prose video { border-radius: 6px; border: 1px solid var(--rule); }
.prose figcaption {
  margin-top: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.5;
  text-wrap: pretty;
}
.table-scroll { overflow-x: auto; margin-block: 1.6em; }
.prose > .table-scroll > table { margin-block: 0; }
.prose table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-block: 1.6em;
}
.prose th, .prose td {
  text-align: left;
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--rule);
}
.prose th { font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-dim); font-weight: 500; }

.post-foot {
  max-width: var(--frame);
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
}
.post-foot a { text-decoration: none; }
.post-foot a:hover { text-decoration: underline; }

/* ---------- footer ---------- */
.footer {
  margin-top: 88px;
  padding-block: 22px 40px;
  border-top: 1px solid var(--rule);
}
.footer-links { display: flex; flex-wrap: wrap; gap: 4px 2px; font-size: 0.88rem; }
.footer-links a { text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }
.footer-links span { margin-inline: 8px; color: var(--text-dim); opacity: 0.6; }
.footer-meta {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ---------- syntax highlighting (Prism token classes) ---------- */
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: var(--text-dim); font-style: italic; }
.token.punctuation { color: var(--text-dim); }
.token.property, .token.tag, .token.constant, .token.symbol, .token.deleted { color: #c0563f; }
.token.boolean, .token.number { color: #9160c4; }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: #3c7a52; }
.token.operator, .token.entity, .token.url { color: var(--text); }
.token.atrule, .token.attr-value, .token.keyword { color: var(--accent); }
.token.function, .token.class-name { color: #b9763d; }
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    .token.property, .token.tag, .token.constant, .token.symbol, .token.deleted { color: #f08f76; }
    .token.boolean, .token.number { color: #c8a5f0; }
    .token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: #86ca9c; }
    .token.function, .token.class-name { color: #e8bb7d; }
  }
}
:root[data-theme="dark"] {
  .token.property, .token.tag, .token.constant, .token.symbol, .token.deleted { color: #f08f76; }
  .token.boolean, .token.number { color: #c8a5f0; }
  .token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: #86ca9c; }
  .token.function, .token.class-name { color: #e8bb7d; }
}

/* ---------- narrow screens ---------- */
@media (max-width: 34rem) {
  .masthead { margin-bottom: 40px; }
  .entry, .ref, .cv-row { grid-template-columns: 1fr; gap: 3px; }
  .entry-note, .ref-title, .ref-meta { grid-column: 1; }
  .ref::before { display: none; }
  .entry-wide { grid-template-columns: 1fr; }
  .cv-when { line-height: 1.5; order: -1; }
  .prose pre { border-radius: 0; margin-inline: -16px; border-inline: none; }
}

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