/* ==========================================================================
   Blog — static pages built by scripts/blog/build.mjs.
   The tokens are copied from src/styles/global.css (the blog does not load the
   app bundle); keep the two in step when the palette changes.
   ========================================================================== */

:root {
  --color-ink: #12293a;
  --color-body: rgba(11, 12, 14, 0.72);
  --color-body-strong: rgba(11, 12, 14, 0.88);
  --color-muted: #5c5c5c;
  --color-cta: #620000;
  --color-cta-hover: #7a0f0f;
  --color-cta-stroke: rgba(98, 0, 0, 0.14);
  --color-cta-stroke-hover: rgba(98, 0, 0, 0.28);
  --color-eyebrow: #620000;
  --color-border: rgba(18, 41, 58, 0.1);
  --color-surface: #f6f6f4;
  --color-code-bg: #f7f7f5;
  --color-bg: #ffffff;
  --color-focus: #2f7fff;
  --font-sans: 'Archivo', ui-sans-serif, 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;
  --radius-card: 24px;
  --radius-btn: 14px;
  --shadow-cta: 0 8px 24px -8px rgba(98, 0, 0, 0.45);
  --shadow-cta-hover: 0 12px 32px -8px rgba(98, 0, 0, 0.55);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --measure: 700px;
  /* Figures sit on the text column; raise this to let them break out wider. */
  --wide: var(--measure);
  --gutter: 20px;
}

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 96px;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-body);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  flex: 1;
}

img,
picture,
video,
svg {
  display: block;
  max-width: 100%;
}

img,
video {
  height: auto;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 200;
  padding: 12px 20px;
  background-color: var(--color-ink);
  color: #fff;
  border-radius: 12px;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 180ms var(--ease-out);
}

.skip-link:focus-visible {
  transform: none;
}

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding-inline: 20px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 180ms var(--ease-out),
    border-color 180ms var(--ease-out),
    box-shadow 180ms var(--ease-out),
    transform 150ms var(--ease-out);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--color-cta);
  color: #fff;
  box-shadow: var(--shadow-cta);
}

.btn-primary:hover {
  background-color: var(--color-cta-hover);
  box-shadow: var(--shadow-cta-hover);
}

.btn-ghost {
  background-color: #fff;
  color: var(--color-cta);
  border-color: var(--color-cta-stroke);
}

.btn-ghost:hover {
  border-color: var(--color-cta-stroke-hover);
}

/* --- Top bar -------------------------------------------------------------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--color-border);
}

.bar-inner {
  max-width: 1312px;
  margin: 0 auto;
  padding: 12px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand img {
  width: 96px;
  height: auto;
}

.bar nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-link {
  font-weight: 500;
  color: var(--color-ink);
  text-decoration: none;
}

.nav-link:hover {
  color: var(--color-cta);
}

.bar .btn {
  height: 38px;
  padding-inline: 16px;
  font-size: 15px;
}

/* --- Post header ---------------------------------------------------------- */

.post-head,
.index-head {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 64px var(--gutter) 32px;
}

.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-eyebrow);
}

.eyebrow a {
  text-decoration: none;
}

.eyebrow a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  color: var(--color-ink);
  font-weight: 600;
  line-height: 1.15;
}

.post-head h1,
.index-head h1 {
  margin-top: 16px;
  font-size: clamp(34px, 5.2vw, 54px);
  font-stretch: 92%;
  letter-spacing: -0.025em;
  line-height: 1.05;
  text-wrap: balance;
}

.dek {
  margin-top: 16px;
  font-size: clamp(19px, 2.4vw, 23px);
  line-height: 1.4;
  color: var(--color-body-strong);
  text-wrap: pretty;
}

.meta {
  margin-top: 20px;
  font-size: 15px;
  color: var(--color-muted);
}

.meta a {
  color: var(--color-ink);
  font-weight: 600;
  text-decoration: none;
}

.meta a:hover {
  text-decoration: underline;
}

/* --- Prose ---------------------------------------------------------------- */

/* A centred reading column, with .wide children breaking out to the media
   width. */
.prose {
  display: grid;
  grid-template-columns:
    1fr
    min(var(--measure), calc(100% - 2 * var(--gutter)))
    1fr;
  font-size: 18px;
  line-height: 1.7;
  color: var(--color-body-strong);
}

.prose > * {
  grid-column: 2;
}

.prose > .wide {
  grid-column: 1 / -1;
  width: min(var(--wide), calc(100% - 2 * var(--gutter)));
  justify-self: center;
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose h2 {
  position: relative;
  margin-top: 2.2em;
  font-size: clamp(24px, 3vw, 30px);
  letter-spacing: -0.015em;
  font-stretch: 95%;
}

.prose h3 {
  margin-top: 1.8em;
  font-size: 21px;
}

.prose h2 + *,
.prose h3 + * {
  margin-top: 0.6em;
}

.anchor {
  position: absolute;
  left: -1.1em;
  width: 1em;
  color: var(--color-cta);
  opacity: 0;
  text-decoration: none;
  transition: opacity 150ms;
}

h2:hover .anchor,
h3:hover .anchor {
  opacity: 0.5;
}

.prose a {
  color: var(--color-cta);
  text-decoration: underline;
  text-decoration-color: var(--color-cta-stroke-hover);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.prose a:hover {
  text-decoration-color: currentColor;
}

.prose strong {
  color: var(--color-ink);
  font-weight: 600;
}

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

.prose li + li {
  margin-top: 0.4em;
}

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

.prose :not(pre) > code {
  padding: 0.12em 0.36em;
  border-radius: 6px;
  background-color: var(--color-code-bg);
  border: 1px solid var(--color-border);
  font-family: var(--font-mono);
  font-size: 0.86em;
  color: var(--color-ink);
}

.prose hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin-block: 2.4em;
}

/* --- Figures -------------------------------------------------------------- */

.prose > figure {
  margin-block: 2em;
}

.prose > figure.hero {
  margin-top: 0;
}

figure .media {
  width: 100%;
  border-radius: 16px;
  background-color: var(--color-surface);
}

figure:not(.hero) .media {
  border: 1px solid var(--color-border);
}

.zoom {
  display: block;
  cursor: zoom-in;
}

figcaption {
  max-width: var(--measure);
  margin: 12px auto 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-muted);
  text-align: center;
  text-wrap: pretty;
}

/* --- Tables --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 14px;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.45;
}

.table-wrap th,
.table-wrap td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
}

.table-wrap th {
  background-color: var(--color-surface);
  color: var(--color-ink);
  font-weight: 600;
  white-space: nowrap;
}

.table-wrap tr:last-child td {
  border-bottom: 0;
}

/* --- Math ----------------------------------------------------------------- */

.math {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0;
  color: var(--color-ink);
}

.math .katex-display {
  margin: 0;
}

/* --- Code blocks ---------------------------------------------------------- */

.code {
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background-color: var(--color-code-bg);
  overflow: hidden;
}

.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 6px 6px 16px;
  border-bottom: 1px solid var(--color-border);
  background-color: #fff;
}

.code-lang {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.code-actions {
  display: flex;
  gap: 6px;
}

.code-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding-inline: 10px;
  border: 1px solid var(--color-border);
  border-radius: 9px;
  background-color: #fff;
  color: var(--color-ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color 150ms var(--ease-out),
    color 150ms var(--ease-out),
    background-color 150ms var(--ease-out);
}

/* Beats `.prose a`, which would otherwise underline the GitHub button red. */
.prose .code-btn {
  color: var(--color-ink);
  text-decoration: none;
}

.prose .code-btn:hover {
  border-color: var(--color-cta-stroke-hover);
  color: var(--color-cta);
}

.code-btn[data-state='done'] {
  border-color: #1a7f37;
  color: #1a7f37;
}

.code pre.shiki {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  background-color: transparent !important;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
}

/* Lines stay inline: Shiki separates them with real newlines, and a block
   line on top of that newline would render every line double-spaced. */
.code pre.shiki code {
  display: block;
  min-width: max-content;
}

/* The prompt is drawn, not typed, so selecting or copying never picks it up. */
.code .line.cmd::before {
  content: '$ ';
  color: var(--color-muted);
  user-select: none;
  -webkit-user-select: none;
}

.code .line.out,
.code .line.out span {
  color: var(--color-muted) !important;
}

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

.post-foot {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 56px auto 0;
  padding: 0 var(--gutter) 96px;
}

.share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

.share-label {
  margin-right: 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.share-btn {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding-inline: 14px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background-color: #fff;
  color: var(--color-ink);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition:
    border-color 150ms var(--ease-out),
    color 150ms var(--ease-out);
}

.share-btn:hover {
  border-color: var(--color-cta-stroke-hover);
  color: var(--color-cta);
}

.share-btn[data-state='done'] {
  border-color: #1a7f37;
  color: #1a7f37;
}

.cta-card {
  margin-top: 40px;
  padding: 32px;
  border-radius: var(--radius-card);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
}

.cta-card h2 {
  margin-top: 10px;
  font-size: 26px;
  letter-spacing: -0.015em;
}

.cta-card p:not(.eyebrow) {
  margin-top: 10px;
  font-size: 17px;
  line-height: 1.6;
  color: var(--color-body-strong);
}

.cta-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.about {
  margin-top: 28px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--color-muted);
}

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

.about a {
  color: var(--color-cta);
  text-underline-offset: 3px;
}

/* --- Blog index ----------------------------------------------------------- */

.blog-index .index-head {
  max-width: 1040px;
  padding-bottom: 40px;
}

.blog-index .dek {
  max-width: 640px;
}

.cards {
  list-style: none;
  max-width: calc(1040px + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 96px;
  display: grid;
  gap: 24px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  text-decoration: none;
  transition:
    border-color 180ms var(--ease-out),
    box-shadow 180ms var(--ease-out);
}

.card:hover {
  border-color: var(--color-cta-stroke-hover);
  box-shadow: 0 16px 40px -24px rgba(18, 41, 58, 0.35);
}

.card-img {
  width: 100%;
  border-radius: 14px;
  aspect-ratio: 1200 / 630;
  object-fit: cover;
}

.card-body {
  padding-right: 16px;
}

.card .meta {
  margin-top: 0;
  font-size: 14px;
}

.card h2 {
  margin-top: 10px;
  font-size: clamp(24px, 2.8vw, 30px);
  letter-spacing: -0.015em;
}

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

.card-dek {
  margin-top: 8px;
  font-size: 17px;
  color: var(--color-body-strong);
}

.card-desc {
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.55;
}

.card-author {
  margin-top: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-ink);
}

.card-role {
  font-weight: 400;
  color: var(--color-muted);
}

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

.site-footer {
  padding: 56px var(--gutter) 32px;
  border-radius: 32px 32px 0 0;
  background-color: var(--color-cta);
  background-image:
    radial-gradient(ellipse 80% 120% at 10% 0%, rgba(255, 110, 90, 0.16) 0%, rgba(255, 110, 90, 0) 100%),
    linear-gradient(to bottom, rgba(26, 0, 0, 0) 35%, rgba(26, 0, 0, 0.6) 100%);
  color: rgba(255, 255, 255, 0.78);
}

.footer-inner {
  max-width: 1312px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 32px;
}

.footer-brand {
  max-width: 380px;
}

.footer-brand img {
  width: 106px;
  height: auto;
}

.footer-brand p {
  margin-top: 16px;
  font-size: 15px;
  line-height: 1.6;
}

.footer-links {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 10px 40px;
  align-content: start;
  font-size: 15px;
}

.footer-links a {
  color: #fff;
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.footer-note {
  max-width: 1312px;
  margin: 40px auto 0;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 14px;
}

/* --- Small screens -------------------------------------------------------- */

@media (max-width: 720px) {
  :root {
    --gutter: 16px;
  }

  .bar nav {
    gap: 14px;
  }

  .post-head,
  .index-head {
    padding-top: 40px;
  }

  .prose {
    font-size: 17px;
  }

  /* Media runs edge to edge on a phone, where every pixel of a diagram counts. */
  .prose > .wide {
    width: 100%;
  }

  figure .media {
    border-radius: 0;
    border-inline: 0 !important;
  }

  figcaption {
    padding-inline: var(--gutter);
  }

  .anchor {
    display: none;
  }

  /* On a phone the code buttons keep their icons and drop the words. */
  .code-btn span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .code-btn {
    width: 36px;
    justify-content: center;
    padding: 0;
  }

  .card {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .card-body {
    padding: 0 4px 8px;
  }

  .cta-card {
    padding: 24px;
  }

  .footer-links {
    grid-template-columns: 1fr 1fr;
    gap: 10px 24px;
  }
}

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