/* ----------------------------------------------------------------------------
   Dark only, on purpose. A low-light terminal palette: kernel black ground,
   graphite surfaces, steel rules, cyan as the primary accent and terminal
   green as the secondary, used only on inline code.

   Fluid from a 320px phone up. Type and gutters scale with the viewport,
   hover effects are gated behind a real pointer, and touch targets grow on
   coarse pointers.
   ------------------------------------------------------------------------- */

:root {
  color-scheme: dark;

  /* ground and surfaces */
  --bg:       #08090b;   /* kernel black */
  --surface:  #101315;   /* graphite, code blocks */
  --panel:    #14181a;   /* steel panel */
  --rule:     #222a2d;   /* steel rule */

  /* text */
  --fg:       #dbe3e5;
  --muted:    #93a1a5;
  --faint:    #78868a;

  /* accents */
  --cyan:     #3fc1d9;   /* primary */
  --green:    #63c76a;   /* secondary, terminal highlight */

  --sel:      #12333b;

  --measure:  36rem;
  --gutter:   clamp(1.1rem, 0.55rem + 1.7vw, 1.5rem);
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

::selection { background: var(--sel); color: var(--fg); }

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

body {
  margin: 0;
  padding: 0 var(--gutter);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: clamp(15.5px, 14.6px + 0.32vw, 17px);
  line-height: 1.68;
  overflow-wrap: break-word;
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

main, header.site, footer.site {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
}

/* main absorbs the slack so the footer sits at the bottom of a short page,
   and carries the gap above the footer so nothing overflows the viewport */
main { flex: 1 0 auto; padding-bottom: clamp(3.5rem, 2rem + 6vw, 6rem); }

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

/* ---------------------------------------------------------------- chrome */

header.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.1rem;
  padding: clamp(1.75rem, 1rem + 2.6vw, 2.75rem) 0 clamp(1.5rem, 0.9rem + 2vw, 2.25rem);
}

header.site .name {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
  margin-right: auto;
}

/* a terminal cursor, not a bullet */
header.site .name::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 14px;
  margin-right: 0.55rem;
  background: var(--cyan);
  vertical-align: -2px;
  box-shadow: 0 0 10px color-mix(in srgb, var(--cyan) 45%, transparent);
}

header.site nav { display: flex; align-items: center; gap: 1.1rem; }

header.site nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 120ms ease;
}

.icon {
  display: inline-flex;
  color: var(--faint);
  /* padding pulled back out by the margin: a bigger hit area, same layout */
  padding: 0.4rem;
  margin: -0.4rem;
  transition: color 120ms ease, transform 120ms ease;
}

.icon svg { display: block; }

footer.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 1.5rem 0 3rem;
  border-top: 1px solid var(--rule);
}

footer.site .mark {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--faint);
  margin-right: auto;
  letter-spacing: 0.02em;
}

footer.site .links { display: flex; gap: 1rem; }

/* ------------------------------------------------------------------ type */

h1, h2, h3 {
  line-height: 1.28;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

h1 { font-size: clamp(1.4rem, 1.2rem + 0.9vw, 1.65rem); margin: 0 0 0.8rem; }
h2 { font-size: 1.1rem; margin: 3rem 0 0.8rem; scroll-margin-top: 1.5rem; }
h3 { font-size: 1rem;   margin: 2rem 0 0.5rem; scroll-margin-top: 1.5rem; }

p, ul, ol { margin: 0 0 1.2rem; text-wrap: pretty; }

ul, ol { padding-left: 1.2rem; }
li { margin-bottom: 0.4rem; }
li::marker { color: var(--faint); }

a {
  color: var(--cyan);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--cyan) 32%, transparent);
  transition: text-decoration-color 120ms ease;
}

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

strong { font-weight: 600; }
em { font-style: italic; }

.lede { font-size: 1.06rem; }

.subtitle {
  font-style: italic;
  color: var(--muted);
  margin: 0 0 0.6rem;
  text-wrap: pretty;
}

.meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--faint);
  margin: 0 0 3rem;
  letter-spacing: 0.01em;
}

hr { border: 0; border-top: 1px solid var(--rule); margin: 3rem 0; }

blockquote {
  margin: 0 0 1.2rem;
  padding-left: 1.1rem;
  border-left: 2px solid var(--rule);
  color: var(--muted);
}

/* ------------------------------------------------------------------ code */

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

/* inline code is the terminal highlight */
code {
  background: var(--panel);
  color: var(--green);
  padding: 0.12em 0.36em;
  border-radius: 3px;
}

pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--cyan);
  padding: 1rem 1.1rem;
  border-radius: 4px;
  overflow-x: auto;
  line-height: 1.55;
}

pre code { background: none; color: var(--fg); padding: 0; }

/* --------------------------------------------------------------- figures */

figure.diagram { margin: 2rem 0 1.6rem; }

/* the image links to itself, so a phone can open it full size */
figure.diagram a { display: block; text-decoration: none; }

figure.diagram img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
  /* white, so that the invert below lands it on black like the page */
  background: #fff;
  /* the drawing is black on white; invert it into the dark palette */
  filter: invert(1);
}

figure.diagram figcaption {
  margin-top: 0.7rem;
  font-size: 0.82rem;
  color: var(--faint);
  text-wrap: pretty;
}

/* ---------------------------------------------------------------- tables */

/* the wrapper scrolls, so the table keeps its own semantics */
.scroll {
  overflow-x: auto;
  margin: 0 0 1.2rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 1rem 0.5rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

th {
  font-family: var(--mono);
  font-weight: 500;
  white-space: nowrap;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
}

tbody tr:last-child td { border-bottom: 0; }

/* ------------------------------------------------------------------ home */

.intro { margin-bottom: clamp(2.25rem, 1.4rem + 3vw, 3.5rem); }
.intro h1 { font-size: clamp(1.55rem, 1.25rem + 1.5vw, 1.9rem); margin-bottom: 1rem; }

/* --------------------------------------------------------------- entries */

.entries { list-style: none; padding: 0; margin: 0; }

.entries li {
  position: relative;
  margin-bottom: 1.6rem;
  padding-bottom: 1.6rem;
  padding-left: 1rem;
  border-bottom: 1px solid var(--rule);
}

.entries li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.6rem;
  width: 2px;
  height: 0.9rem;
  background: var(--rule);
  transition: background 160ms ease, height 200ms cubic-bezier(.22,.61,.36,1);
}

.entries li:last-child { border-bottom: 0; }

.entries .when {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.15rem;
}

.entries .title {
  font-weight: 600;
  display: block;
  color: var(--fg);
  text-decoration: none;
  transition: color 140ms ease, transform 160ms cubic-bezier(.22,.61,.36,1);
}

.entries p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.94rem; }

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

.post h2 { margin-top: 3rem; }

.back { margin-top: clamp(2.5rem, 1.5rem + 4vw, 4rem); font-size: 0.88rem; font-family: var(--mono); }

/* ---------------------------------------------------- pointer and device */

/* hover states only where a pointer can actually hover, so a tap on a phone
   does not leave one stuck on */
@media (hover: hover) and (pointer: fine) {
  header.site nav a:hover { color: var(--cyan); }
  .icon:hover { color: var(--cyan); transform: translateY(-1px); }
  a:hover { text-decoration-color: currentColor; }
  .entries li:hover::before { background: var(--cyan); height: 1.45rem; }
  .entries li:hover .title { color: var(--cyan); transform: translateX(2px); }
  header.site nav a:not(.icon):hover::after { transform: scaleX(1); }
  .back a:hover::before { transform: translateX(-3px); }
}

/* fingers need a bigger target than a mouse does; widen the nav to match so
   the enlarged hit areas do not overlap */
@media (pointer: coarse) {
  header.site nav { gap: 1.6rem; }
  footer.site .links { gap: 1.6rem; }
  .icon { padding: 0.75rem; margin: -0.75rem; }
}

/* ---------------------------------------------------------------- motion */
/*
   Small and cheap. Everything here is transform or opacity so it stays on the
   compositor, and all of it is switched off under prefers-reduced-motion.
*/

@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.28; } }

@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

/* the block cursor blinks, slowly */
header.site .name::before { animation: blink 1.15s step-end infinite; }

/* content settles in on load, a beat apart */
main > * { animation: rise 460ms cubic-bezier(.22,.61,.36,1) both; }
main > *:nth-child(1) { animation-delay:  40ms; }
main > *:nth-child(2) { animation-delay:  90ms; }
main > *:nth-child(3) { animation-delay: 140ms; }
main > *:nth-child(4) { animation-delay: 190ms; }
main > *:nth-child(5) { animation-delay: 240ms; }
main > *:nth-child(n+6) { animation-delay: 280ms; }

header.site, footer.site { animation: rise 400ms ease-out both; }
footer.site { animation-delay: 120ms; }

/* nav underline sweeps out from the left */
header.site nav a:not(.icon) { position: relative; }

header.site nav a:not(.icon)::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -3px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 180ms cubic-bezier(.22,.61,.36,1);
}

/* back link */
.back a { display: inline-block; }
.back a::before {
  content: "\2190";
  display: inline-block;
  margin-right: 0.45rem;
  transition: transform 160ms cubic-bezier(.22,.61,.36,1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  main > *, header.site, footer.site { opacity: 1; transform: none; }
}

/* ----------------------------------------------------------------- print */

@media print {
  :root {
    --bg: #fff; --fg: #000; --muted: #444; --faint: #555;
    --rule: #ccc; --cyan: #000; --green: #000; --surface: #f4f4f4; --panel: #f4f4f4;
  }
  header.site nav, footer.site, .back { display: none; }
  header.site .name::before { display: none; }
  body { font-size: 11pt; padding: 0; display: block; min-height: 0; }
  main { max-width: none; padding-bottom: 0; }
  a { text-decoration: none; }
  code { color: #000; }
  pre { border-left-width: 1px; }
  .scroll, pre { overflow: visible; }
  figure.diagram img { filter: none; border-color: #ccc; }
  pre, table { break-inside: avoid; }
}
