/* ==========================================================================
   egent.dev — site stylesheet, dark.
   Derived from the CV (~/Documents/cv/cv.css): same typefaces, same column
   of mono labels beside the content, same hairlines and sparing accent.
   To restyle, the tokens under :root are the only knobs worth touching.
   ========================================================================== */

/* ---------- Fonts (self-hosted, same files as the CV) --------------------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Inter-normal-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Inter-normal-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Inter-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/Inter-italic-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("fonts/JetBrainsMono-normal-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url("fonts/JetBrainsMono-normal-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens -------------------------------------------------------- */

/* The CV's palette, inverted: its ink becomes the ground, its backdrop grey
   becomes the text. Grey steps and the accent hue (229°) are kept; the accent
   is lifted in lightness so it reads on black. Contrast on --paper:
   ink 15.4:1, ink-soft 8.0:1, ink-faint 5.6:1, accent 6.6:1. */
:root {
  --paper: #0f1115;      /* page ground */
  --raised: #15181e;     /* code blocks */
  --ink: #e6e8ec;        /* body text */
  --ink-soft: #a4a9b3;   /* secondary text */
  --ink-faint: #868c98;  /* dates, markers */
  --rule: #252932;       /* hairlines */
  --rule-firm: #e6e8ec;  /* one firm rule per page, under its heading */
  --accent: #7e93f1;     /* used sparingly: labels, hover */
  --select: rgb(126 147 241 / 0.28);

  --sans: "Inter", "Inter Variable", system-ui, -apple-system, "Segoe UI",
    Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 52rem;      /* total content width */
  --label-col: 9.5rem;   /* left column holding labels: years, dates */
  --gutter: 2.25rem;
  --page-x: 1.5rem;
  --hero-y: clamp(3rem, 9vh, 6rem); /* space above a page's heading */

  color-scheme: dark;
}

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

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

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  font-feature-settings: "calt", "ss03", "cv05", "cv08"; /* Inter: rounder quotes, plainer l */
  font-kerning: normal;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased; /* light-on-dark text otherwise renders heavy */
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--select);
  color: var(--ink);
}

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

a {
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

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

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

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

/* Header, main and footer; main grows so the footer sits at the bottom. */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: calc(var(--measure) + 2 * var(--page-x));
  margin: 0 auto;
  padding: 0 var(--page-x);
}

.page > main {
  flex: 1;
}

/* The CV's section layout: a mono label on the left, content on the right,
   first lines sharing a baseline. */
.split {
  display: grid;
  grid-template-columns: var(--label-col) minmax(0, 1fr);
  column-gap: var(--gutter);
  align-items: baseline;
}

.label {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- Site header and footer ---------------------------------------- */

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

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

/* An <img> of sphere.png, which ball.js swaps for a canvas drawing the same
   ball so it can animate it. It rolls over the name in some animations, so
   it sits above it. */
.wordmark .ball {
  display: block;
  position: relative;
  z-index: 1;
  width: 1.375rem;
  height: 1.375rem;
}

/* Clicking the ball plays it rather than going home, so pointing at it
   should not light up the name as a link. */
.wordmark:has(.ball:hover) {
  color: var(--ink);
}

.ball-pending .wordmark > * {
  opacity: 0;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  margin-top: 3rem;
  padding: 1.25rem 0 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

/* ---------- Home: hero ---------------------------------------------------- */

/* The home page is the hero alone: the ASCII ball, then name, headline and
   links as on the CV's masthead, centred in the window above the footer. */
.home main {
  display: flex;
  align-items: center;
}

.hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 2.5rem;
  width: 100%;
  padding: 3rem 0;
}

.hero-name {
  font-size: clamp(2.25rem, 1.5rem + 3.2vw, 3.25rem);
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.hero-title {
  position: relative;
  max-width: 30em;
  margin-top: 1rem;
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.3125rem);
  font-weight: 450;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75em;
  margin-top: 1.5rem;
  list-style: none;
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-soft);
}

/* Links on one line, a bar between them; the bar is not read out. */
.hero-links li + li::before {
  content: "|" / "";
  margin-right: 0.75em;
  color: var(--ink-faint);
}

/* stream.js: the full text holds the layout, invisibly; the streamed copy
   is laid over it, token by token, behind a block cursor. */
.stream-pending .hero-title,
.stream-ghost {
  color: transparent;
}

.stream-live {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stream-live .token {
  animation: token-in 0.24s ease-out both;
}

@keyframes token-in {
  from {
    opacity: 0;
    filter: blur(3px);
  }
}

.stream-caret {
  display: inline-block;
  width: 0.5em;
  height: 1.05em;
  margin-left: 0.1em;
  margin-right: -0.6em; /* takes no room in the line, so it never wraps onto one of its own */
  vertical-align: -0.17em;
  background: var(--accent);
  transition: opacity 0.6s ease;
}

.stream-caret.waiting {
  animation: caret-blink 1s steps(1) infinite;
}

.stream-caret.gone {
  opacity: 0;
  animation: none;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

/* ascii.js draws the ball on this canvas: 56 columns of JetBrains Mono's
   0.6em advance by 28 rows of 1.2em lines, which is square. font-size sets
   the character size, and so the ball's. */
.ascii {
  display: block;
  justify-self: start;
  width: 33.6em;
  height: 33.6em;
  font-size: 0.625rem;
  cursor: grab;
  touch-action: none; /* dragging turns the ball instead of scrolling the page */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ascii.dragging {
  cursor: grabbing;
}

/* ---------- Blog archive (not linked yet) --------------------------------- */

/* One row per year: the year in the label column, its posts beside it. */
.year {
  padding: 1.75rem 0 2rem;
}

.year + .year {
  border-top: 1px solid var(--rule);
}

.posts {
  list-style: none;
}

.posts li + li {
  margin-top: 1.375rem;
}

.posts a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  align-items: baseline;
}

.posts a:hover {
  color: inherit;
}

.posts h3 {
  font-size: 1.0625rem;
  font-weight: 620;
  line-height: 1.45;
  letter-spacing: -0.012em;
  text-wrap: pretty;
  transition: color 0.15s ease;
}

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

.posts time {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.posts p {
  grid-column: 1 / -1;
  margin-top: 0.125rem;
  color: var(--ink-soft);
  text-wrap: pretty;
}

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

.post-header {
  padding: var(--hero-y) 0 2rem;
  border-bottom: 1px solid var(--rule-firm);
}

.post-header h1 {
  font-size: clamp(2rem, 1.4rem + 2.6vw, 2.75rem);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.032em;
  text-wrap: balance;
}

.post-header .dek {
  max-width: 40rem;
  margin-top: 1rem;
  font-size: 1.1875rem;
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--ink-soft);
  text-wrap: pretty;
}

/* Body text sits in the right-hand column; headings and rules span both,
   so their hairline runs the full width like the CV's section rules. */
.post-body {
  display: grid;
  grid-template-columns: var(--label-col) minmax(0, 1fr);
  column-gap: var(--gutter);
  padding: 2.25rem 0 1rem;
  font-size: 1.0625rem;
  line-height: 1.7;
}

.post-body > * {
  grid-column: 2;
  min-width: 0;
}

.post-body > * + * {
  margin-top: 1.15em;
}

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

.post-body a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  text-decoration-color: var(--ink-faint);
}

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

.post-body > h2 {
  grid-column: 1 / -1;
  margin-top: 2.75rem;
  padding: 1.75rem 0 0 calc(var(--label-col) + var(--gutter));
  border-top: 1px solid var(--rule);
  font-size: 1.375rem;
  font-weight: 620;
  line-height: 1.3;
  letter-spacing: -0.018em;
  text-wrap: balance;
}

.post-body > h3 {
  margin-top: 2.25rem;
  font-size: 1.125rem;
  font-weight: 620;
  line-height: 1.4;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

.post-body > h2 + *,
.post-body > h3 + * {
  margin-top: 0.75em;
}

.post-body ul,
.post-body ol {
  list-style: none;
}

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

/* Hanging markers, as in the CV: a dash for bullets, 01 02 … for steps. */
.post-body li {
  padding-left: 1.6em;
  text-indent: -1.6em;
}

.post-body li::before {
  display: inline-block;
  width: 1.6em;
  text-indent: 0;
  color: var(--ink-faint);
}

.post-body ul > li::before {
  content: "–";
}

.post-body ol {
  counter-reset: step;
}

.post-body ol > li {
  counter-increment: step;
}

.post-body ol > li::before {
  content: counter(step, decimal-leading-zero);
  width: 2em; /* = the 1.6em hanging indent, at this 0.8em size */
  font-family: var(--mono);
  font-size: 0.8em;
}

.post-body blockquote {
  padding-left: 1.25rem;
  border-left: 2px solid var(--ink-faint);
  color: var(--ink-soft);
}

.post-body hr {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2.75rem 0 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

.post-body hr + * {
  margin-top: 2.75rem;
}

.post-body code {
  padding: 0.1em 0.35em;
  background: var(--raised);
  font-family: var(--mono);
  font-size: 0.85em;
}

.post-body pre {
  overflow-x: auto;
  padding: 1rem 1.25rem;
  background: var(--raised);
  border: 1px solid var(--rule);
  font-size: 0.875rem;
  line-height: 1.65;
  tab-size: 4;
}

.post-body pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.post-body figcaption {
  margin-top: 0.625rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-faint);
}

/* A figure that should break out into the label column. */
.post-body > .wide {
  grid-column: 1 / -1;
}

/* ---------- Narrow screens ------------------------------------------------ */

@media (max-width: 44rem) {
  :root {
    --page-x: 1rem;
  }

  .site-header {
    padding: 1.25rem 0;
  }

  /* Labels move above their content. */
  .split {
    display: block;
  }

  .split > .label {
    display: block;
    margin-bottom: 0.875rem;
  }

  .year {
    padding: 1.5rem 0 1.75rem;
  }

  /* The ball goes above the name, a little smaller. */
  .hero {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 1.5rem;
  }

  .ascii {
    font-size: 0.4375rem;
  }

  .post-body {
    display: block;
  }

  .post-body > h2 {
    padding-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  a,
  .posts h3 {
    transition: none;
  }
}
