/*
 * Site: a compact Swiss grid.
 *
 * One family (Inter, variable opsz + wght), one accent (a red square),
 * one grid: 12 columns inside a 1024px measure. Labels hang in columns
 * 1-3 and content runs on the column-4 axis, baseline to baseline.
 * Page styles (home.css, post.css) build on these tokens and classes.
 */

@font-face {
  font-family: "Inter";
  src: url("/fonts/InterVariable-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Metric-matched fallback so the swap to Inter does not shift the layout. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Liberation Sans"), local("Arimo");
  ascent-override: 90.44%;
  descent-override: 22.52%;
  line-gap-override: 0%;
  size-adjust: 107.12%;
}

:root {
  color-scheme: light dark;
  interpolate-size: allow-keywords;

  --paper: #f4f4f1;
  --ink: #111110;
  --muted: #45453f;
  --dim: #6d6d66;
  --line: #d6d6d0;
  --tint: #e9e9e4;
  --accent: #d8231a;
  --grid-fill: rgb(216 35 26 / 0.06);
  --grid-edge: rgb(216 35 26 / 0.25);

  --font: "Inter", "Inter Fallback", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 1024px;
  --margin: clamp(16px, 4vw, 40px);
  --gutter: 16px;
  --section-gap: clamp(56px, 8vw, 80px);

  --fs-meta: 0.8125rem;
  --fs-row: 0.9375rem;
  --fs-lead: clamp(1.125rem, 1.8vw, 1.3125rem);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e0e0d;
    --ink: #ededea;
    --muted: #b8b8b2;
    --dim: #8c8c85;
    --line: #2a2a27;
    --tint: #1b1b19;
    --accent: #ff4a3d;
    --grid-fill: rgb(255 74 61 / 0.07);
    --grid-edge: rgb(255 74 61 / 0.3);
  }
}

/* ---------- Base ---------- */

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

html {
  overflow-x: clip;
  background: var(--paper);
  color: var(--ink);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-row);
  font-kerning: normal;
  font-optical-sizing: auto;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd,
figure,
blockquote,
pre {
  margin: 0;
}

h1,
h2,
h3 {
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  line-height: inherit;
}

p {
  text-wrap: pretty;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

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

::selection {
  background: var(--accent);
  color: #fff;
}

code {
  font-family: var(--mono);
}

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

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  padding: 8px 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-meta);
  transform: translateY(calc(-100% - 24px));
}

.skip-link:focus {
  color: var(--paper);
  transform: none;
}

/* ---------- Grid ---------- */

.shell {
  width: min(100% - 2 * var(--margin), var(--measure));
  margin-inline: auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
}

/* A row inside the content columns: nine tracks that land on the page grid. */
.row {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  column-gap: var(--gutter);
  align-items: baseline;
}

/* ---------- Links & arrows ---------- */

.link {
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
  transition: color 160ms ease, text-decoration-color 160ms ease;
}

.link:hover {
  text-decoration-color: currentColor;
}

.arrow {
  display: inline-block;
  margin-left: 0.25em;
  transition: transform 240ms var(--ease-out);
}

.arrow--back {
  margin: 0 0.25em 0 0;
}

a:hover .arrow--out {
  transform: translate(0.1em, -0.1em);
}

a:hover .arrow--in {
  transform: translateX(0.18em);
}

a:hover .arrow--back {
  transform: translateX(-0.18em);
}

a:hover .arrow--down {
  transform: translateY(0.12em);
}

a:hover .arrow--up {
  transform: translateY(-0.12em);
}

/* ---------- Masthead ---------- */

.masthead {
  padding-top: clamp(24px, 5vw, 48px);
  align-items: baseline;
}

.masthead__name {
  grid-column: 1 / 4;
  justify-self: start;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.mark {
  display: inline-block;
  width: 0.34em;
  height: 0.34em;
  margin-left: 0.12em;
  background: var(--accent);
}

.masthead__role {
  grid-column: 4 / 9;
  color: var(--dim);
}

.masthead__nav {
  display: flex;
  grid-column: 9 / -1;
  justify-content: flex-end;
  gap: 20px;
}

.masthead__nav [aria-current] {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
}

/* ---------- Page intro (blog index, article header) ---------- */

.page-intro {
  margin-top: clamp(56px, 9vw, 96px);
  align-items: baseline;
  row-gap: 12px;
}

.page-intro__aside {
  grid-column: 1 / 4;
  color: var(--dim);
}

.page-intro__body {
  display: grid;
  grid-column: 4 / 11;
  gap: 14px;
}

.page-intro h1 {
  font-size: clamp(1.625rem, 3.4vw, 2.25rem);
  font-weight: 600;
  letter-spacing: -0.028em;
  line-height: 1.15;
  text-wrap: balance;
}

.page-intro__dek {
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.55;
}

/* ---------- Sections ---------- */

.section {
  margin-top: var(--section-gap);
  padding-top: 12px;
  row-gap: 12px;
  align-items: baseline;
  border-top: 1px solid var(--line);
  scroll-margin-top: 24px;
}

.section__label {
  grid-column: 1 / 4;
  color: var(--dim);
}

.section__more {
  display: block;
  width: fit-content;
  margin-top: 2px;
  color: var(--ink);
  font-size: var(--fs-meta);
}

.section__body {
  grid-column: 4 / -1;
  min-width: 0;
}

/* ---------- Post rows (home, blog index, related reading) ---------- */

.posts__row {
  row-gap: 2px;
  padding-block: 5px;
}

.posts__title {
  grid-column: 1 / 8;
  transition: color 160ms ease;
}

.posts__summary {
  grid-column: 1 / 8;
  color: var(--muted);
}

.posts__meta {
  grid-column: 1 / 8;
  margin-top: 4px;
  font-size: var(--fs-meta);
}

.posts__date {
  grid-column: 8 / -1;
  grid-row: 1;
  justify-self: end;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.posts__row:hover {
  color: inherit;
}

.posts__row:hover .posts__title {
  color: var(--accent);
}

.posts--detailed .posts__row {
  padding-block: 12px;
}

.posts--detailed .posts__title {
  font-weight: 600;
}

/* ---------- Key / value rows (About, CV) ---------- */

.kv__row {
  padding-block: 5px;
}

.kv__row dt {
  grid-column: 1 / 4;
  color: var(--dim);
}

.kv__row dd {
  grid-column: 4 / -1;
  min-width: 0;
}

/* ---------- Footer ---------- */

.footer {
  margin-top: calc(var(--section-gap) * 1.5);
  padding-block: 12px 40px;
  row-gap: 6px;
  align-items: baseline;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: var(--fs-meta);
}

.footer__copy {
  grid-column: 1 / 4;
}

.footer__colophon {
  grid-column: 4 / 10;
}

.footer__tools {
  display: flex;
  grid-column: 10 / -1;
  justify-content: flex-end;
  gap: 20px;
}

.footer__grid-toggle {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.footer__grid-toggle:hover,
.footer__grid-toggle[aria-pressed="true"] {
  color: var(--accent);
}

/* ---------- Grid overlay (toggled from the footer) ---------- */

.grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.grid-overlay[data-visible] {
  opacity: 1;
}

.grid-overlay .grid {
  height: 100%;
}

.grid-overlay span {
  border-inline: 1px solid var(--grid-edge);
  background: var(--grid-fill);
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  .mark {
    animation: mark-in 500ms var(--ease-out) 200ms both;
  }

  .page-intro__body {
    animation: fade-up 700ms var(--ease-out) both;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

@keyframes mark-in {
  from {
    transform: scale(0);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translate3d(0, 8px, 0);
  }
}

/* ---------- Mobile: four columns, labels above their content ---------- */

@media (max-width: 699px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .row {
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: 2px;
  }

  .grid-overlay span:nth-child(n + 5) {
    display: none;
  }

  .masthead__name {
    grid-column: 1 / 2;
  }

  .masthead__role {
    display: none;
  }

  .masthead__nav {
    grid-column: 2 / -1;
    gap: 14px;
  }

  .page-intro__aside,
  .page-intro__body,
  .section__label,
  .section__body,
  .footer__copy,
  .footer__colophon,
  .footer__tools {
    grid-column: 1 / -1;
  }

  .section__label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
  }

  .section__more {
    margin-top: 0;
  }

  .posts__title,
  .posts__summary,
  .posts__meta {
    grid-column: 1;
  }

  .posts__date {
    grid-column: 2;
    padding-left: 12px;
  }

  .posts__row {
    padding-block: 7px;
  }

  .kv__row dt {
    grid-column: 1;
  }

  .kv__row dd {
    grid-column: 1 / -1;
  }

  .footer__tools {
    justify-content: flex-start;
  }
}
