/* The public site. The tokens are T.O.M.S's dashboard's, with a light palette added as the
   default; dark follows the system until the reader chooses, and the choice is kept. */

@font-face {
  font-family: 'Roboto Variable';
  src: url('/assets/fonts/roboto-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-raised: #eef0f2;
  --border: #e1e4e8;
  --border-strong: #c9ced4;
  --text: #15181c;
  --text-muted: #56606a;
  /* Every text colour is at least 4.5:1 on every surface it sits on (WCAG AA). */
  --text-dim: #646d77;
  --accent: #2c6aad;
  --accent-text: #ffffff;
  --code-bg: #eef0f2;
  /* Code tokens, each at least 4.5:1 on --code-bg. */
  --code-comment: #5c6670;
  --code-keyword: #8a2fb8;
  --code-string: #23702a;
  --code-number: #a14400;
  --code-function: #1f5fa8;
  --code-type: #7a5000;
  --code-tag: #b0283c;
  --code-punctuation: #56606a;

  --radius: 14px;
  --radius-sm: 8px;
  --gap: 16px;
  /* Lines of running text stay readable; everything else takes the window's width. */
  --measure: 48rem;
  --gutter: clamp(16px, 4vw, 48px);

  --font: 'Roboto Variable', Roboto, ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0c0e10;
  --surface: #15181c;
  --surface-raised: #1c2026;
  --border: #272c33;
  --border-strong: #3a424b;
  --text: #e8ebee;
  --text-muted: #939da7;
  --text-dim: #7f8994;
  --accent: #4f8fd6;
  --accent-text: #0c0e10;
  --code-bg: #1c2026;
  --code-comment: #8a949e;
  --code-keyword: #d39cf0;
  --code-string: #9fd38a;
  --code-number: #f0a868;
  --code-function: #7fb6f0;
  --code-type: #e8c66a;
  --code-tag: #f08a9a;
  --code-punctuation: #a9b2bb;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0c0e10;
    --surface: #15181c;
    --surface-raised: #1c2026;
    --border: #272c33;
    --border-strong: #3a424b;
    --text: #e8ebee;
    --text-muted: #939da7;
    --text-dim: #7f8994;
    --accent: #4f8fd6;
    --accent-text: #0c0e10;
    --code-bg: #1c2026;
    --code-comment: #8a949e;
    --code-keyword: #d39cf0;
    --code-string: #9fd38a;
    --code-number: #f0a868;
    --code-function: #7fb6f0;
    --code-type: #e8c66a;
    --code-tag: #f08a9a;
    --code-punctuation: #a9b2bb;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

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

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

.skip {
  position: absolute;
  left: -999px;
}

.skip:focus {
  left: 16px;
  top: 16px;
  padding: 8px 12px;
  background: var(--surface);
  z-index: 10;
}

/* ---------------------------------------------------------------------- page */

/* The page is exactly the window. The bars sit at its top and bottom and never move; only
   the screen between them scrolls, and its scrolling stops at its own ends rather than
   dragging the page or the bars with it. */
html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.page {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar,
.bottombar {
  flex: none;
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* The main landmark is the scroller itself, so the skip link, which focuses it, leaves the
   keyboard's Page Down and arrows scrolling it. */
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* A heading jumped to lands clear of the screen's top edge. */
  scroll-padding-top: 16px;
}

main:focus {
  outline: none;
}

/* Read by a screen reader, not shown. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------- top bar */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 56px;
  padding: 0 var(--gutter);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

/* The mark, drawn in the text's colour so it follows the theme; the file is black. */
.wordmark::before {
  content: '';
  width: 1.45rem;
  height: 1.7rem;
  background-color: currentColor;
  -webkit-mask: url('/assets/icon.svg') center / contain no-repeat;
  mask: url('/assets/icon.svg') center / contain no-repeat;
}

.topbar ul,
.bottombar ul {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* The site's own links, small, at the right of the first row. */
.utility {
  margin-left: auto;
}

/* A standalone page has no links between the two, so the switch keeps the right edge. */
.wordmark + .theme-switch {
  margin-left: auto;
}

.utility ul {
  gap: 4px 18px;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 0.9rem;
}

.utility a,
.sections a,
.subbar a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}

.utility a:hover,
.sections a:hover,
.subbar a:hover,
.sections a[aria-current],
.subbar a[aria-current] {
  color: var(--text);
}

/* The sections, and under one the sections within it. On a narrow screen a row too long
   for it scrolls sideways rather than piling up under the bar. */
.sections,
.subbar {
  border-top: 1px solid var(--border);
}

.sections ul,
.subbar ul {
  gap: 24px;
  padding: 0 var(--gutter);
  overflow-x: auto;
  scrollbar-width: none;
}

.sections ul::-webkit-scrollbar,
.subbar ul::-webkit-scrollbar {
  display: none;
}

.sections a {
  display: block;
  padding: 10px 0;
}

.sections a[aria-current] {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.subbar {
  background: var(--surface-raised);
}

.subbar a {
  display: block;
  padding: 7px 0;
  font-size: 0.95rem;
}

/* The theme switch: the knob is the sun at the left for light and slides right to become
   the moon for dark. Its position follows the theme in force, from the first frame, before
   the script has marked the switch checked. */
.theme-switch {
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-raised);
  cursor: pointer;
}

.theme-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e8a317;
  transition:
    transform 0.2s ease,
    background-color 0.2s ease,
    box-shadow 0.2s ease;
}

:root[data-theme='dark'] .theme-knob {
  transform: translateX(20px);
  background: transparent;
  box-shadow: inset 7px -3px 0 0 var(--text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-knob {
    transform: translateX(20px);
    background: transparent;
    box-shadow: inset 7px -3px 0 0 var(--text);
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-knob {
    transition: none;
  }
}

/* ---------------------------------------------------------------- bottom bar */

.bottombar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 24px;
  padding: 10px var(--gutter);
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.4;
}

.copyright {
  margin: 0;
}

.contact {
  gap: 4px 20px;
  flex-wrap: wrap;
}

.contact a {
  color: var(--text-muted);
  text-decoration: none;
}

.contact a:hover {
  color: var(--text);
  text-decoration: underline;
}

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

main {
  padding: 32px var(--gutter) 48px;
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.list > h1 {
  font-size: 2rem;
  margin: 0 0 16px;
}

.intro {
  max-width: var(--measure);
  margin-bottom: 32px;
  color: var(--text-muted);
}

/* As many columns of cards as the window holds, each at least 20rem or the full width. */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr));
  gap: 24px;
}

.empty {
  color: var(--text-dim);
}

.card {
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.card-text {
  padding: 16px 20px 20px;
}

.card h2 {
  font-size: 1.35rem;
  margin: 0 0 6px;
}

.card h2 a {
  color: var(--text);
  text-decoration: none;
}

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

.meta {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.meta .author {
  color: var(--text-muted);
  font-weight: 500;
}

.meta time {
  margin-left: 6px;
}

.summary {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.tags a {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
}

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

.pager,
.neighbours {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.tag-index {
  list-style: none;
  padding: 0;
  columns: 2 12rem;
}

.tag-index .count {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.notice {
  max-width: var(--measure);
  margin: 64px auto;
  text-align: center;
}

.preview-banner {
  margin: 0 0 24px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 500;
}

/* ------------------------------------------------------------------- article */

/* An article takes the window's width, inset a little from the edges, more as the window
   widens (about 120px a side at 1600, nothing on a phone); the hero and the text alike. */
.post {
  --inset: max(0px, 10vw - 40px);
}

.post > * {
  margin-left: var(--inset);
  margin-right: var(--inset);
}

.title {
  margin-top: 0;
  margin-bottom: 32px;
}

.title h1 {
  font-size: clamp(2rem, 5vw, 2.9rem);
  margin: 8px 0 12px;
}

.standfirst {
  font-size: 1.2rem;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.crumbs {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.crumbs a {
  color: var(--text-muted);
  text-decoration: none;
}

.updated {
  margin-left: 10px;
}

/* A hero: the picture fills the block and the words sit on a darkened lower edge. */
.title.has-hero {
  position: relative;
  min-height: clamp(16rem, 42vh, 30rem);
  display: flex;
  align-items: flex-end;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0c0e10;
}

.title.has-hero .hero {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title.has-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(12, 14, 16, 0.15) 0%, rgba(12, 14, 16, 0.85) 100%);
}

.title.has-hero .title-text {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 24px 28px;
  color: #e8ebee;
}

.title.has-hero .standfirst,
.title.has-hero .meta,
.title.has-hero .meta .author,
.title.has-hero .crumbs,
.title.has-hero .crumbs a {
  color: #c9ced4;
}

.body {
  overflow-wrap: break-word;
}

.body h2 {
  font-size: 1.6rem;
  margin-top: 2.2em;
}

.body h3 {
  font-size: 1.3rem;
  margin-top: 1.8em;
}

.body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.body blockquote {
  margin: 1.5em 0;
  padding: 0 0 0 18px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.body pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  line-height: 1.5;
}

.body pre code {
  background: none;
  padding: 0;
}

/* Code coloured by Prism (assets/prism), in the site's own palette. */
.body .token.comment,
.body .token.prolog,
.body .token.doctype,
.body .token.cdata {
  color: var(--code-comment);
  font-style: italic;
}

.body .token.punctuation,
.body .token.operator {
  color: var(--code-punctuation);
}

.body .token.keyword,
.body .token.atrule,
.body .token.boolean,
.body .token.important {
  color: var(--code-keyword);
}

.body .token.string,
.body .token.char,
.body .token.attr-value,
.body .token.regex,
.body .token.inserted {
  color: var(--code-string);
}

.body .token.number,
.body .token.constant,
.body .token.symbol {
  color: var(--code-number);
}

.body .token.function {
  color: var(--code-function);
}

.body .token.class-name,
.body .token.builtin {
  color: var(--code-type);
}

.body .token.tag,
.body .token.selector,
.body .token.property,
.body .token.attr-name,
.body .token.deleted {
  color: var(--code-tag);
}

.body .table {
  overflow-x: auto;
}

.body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
}

.body th,
.body td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}

.body li.task {
  list-style: none;
}

.body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

/* A carousel: a row of thumbnails that scrolls sideways and snaps to each. */
.body .carousel {
  display: flex;
  gap: 10px;
  margin: 1.5em 0;
  padding-bottom: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
}

.body .carousel a {
  flex: none;
  scroll-snap-align: start;
  border-radius: var(--radius-sm);
}

.body .carousel img {
  display: block;
  width: auto;
  height: 11rem;
  max-width: none;
  object-fit: cover;
  background: var(--surface-raised);
}

@media (max-width: 600px) {
  .body .carousel img {
    height: 8rem;
  }
}

/* The dialog gallery.js opens over the page: the image as large as the window allows. */
.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #e8ebee;
}

.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.lightbox::backdrop {
  background: rgba(8, 10, 12, 0.92);
}

.lightbox figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
  min-width: 0;
}

.lightbox img {
  display: block;
  max-width: calc(100vw - 128px);
  max-height: calc(100dvh - 96px);
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
}

.lightbox figcaption {
  max-width: 60ch;
  font-size: 0.95rem;
  text-align: center;
}

.lightbox button {
  flex: none;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #e8ebee;
  font: inherit;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox button:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox .lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

@media (max-width: 600px) {
  .lightbox img {
    max-width: 100vw;
  }

  .lightbox .lightbox-previous,
  .lightbox .lightbox-next {
    position: absolute;
    bottom: 16px;
  }

  .lightbox .lightbox-previous {
    left: 16px;
  }

  .lightbox .lightbox-next {
    right: 16px;
  }
}

.post-foot {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.neighbours a {
  max-width: 48%;
  text-decoration: none;
}

.neighbours a span {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.neighbours a[rel='next'] {
  margin-left: auto;
  text-align: right;
}

/* -------------------------------------------------------------------- narrow */

@media (max-width: 600px) {
  .topbar-row {
    gap: 12px;
    min-height: 52px;
  }

  .wordmark {
    font-size: 1.15rem;
  }

  .utility ul {
    gap: 4px 14px;
    font-size: 0.85rem;
  }

  main {
    padding-top: 20px;
    padding-bottom: 32px;
  }

  .title.has-hero {
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
    border-radius: 0;
  }

  .title.has-hero .title-text {
    padding: 20px var(--gutter);
  }

  .bottombar {
    padding-top: 8px;
    padding-bottom: 8px;
    font-size: 0.8rem;
  }
}
