/* davidjk.net — see DESIGN.md for the reasoning behind these choices. */

/* ---- Palette and type ---- */

/* Fira Code has no italic; the browser slants the regular for italic text. */
@font-face {
  font-family: "Fira Code";
  src: url("fonts/FiraCode-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Fira Code";
  src: url("fonts/FiraCode-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #fbfbf8;
  --ink: #1b1b1b;
  --muted: #5f5f5a;
  --rule: #1b1b1b;
  --hairline: #d9d9d3;
  --code-bg: #f1f1ec;

  --mono: "Fira Code", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas,
    "DejaVu Sans Mono", "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;

  --measure: 42rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151514;
    --ink: #e4e4de;
    --muted: #9a9a93;
    --rule: #e4e4de;
    --hairline: #34342f;
    --code-bg: #1f1f1d;
  }
}

/* ---- Page ---- */

body {
  margin: 0;
  padding: 0 1.25rem;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.65 var(--sans);
  font-variant-ligatures: no-contextual;
  -webkit-text-size-adjust: 100%;
}

/* Coding ligatures (-> becomes an arrow) only where they are wanted. */
code,
pre,
.ligatures {
  font-variant-ligatures: contextual;
}

.masthead,
main,
.colophon {
  max-width: var(--measure);
  margin-inline: auto;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

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

/* ---- Masthead: the resume letterhead ---- */

.masthead {
  padding-top: 3rem;
  text-align: center;
}

.masthead-name {
  display: inline-block;
  margin-bottom: 0.75rem;
  font: 2.25rem/1.2 var(--mono);
  text-decoration: none;
}

/* First visit: "davidjk.net" types itself out behind a blinking cursor.
   Each letter takes no space until it's typed, so the centred name widens and
   re-centres with every keystroke, like centred text in an editor. In a
   monospace font every letter is exactly 1ch wide, and the cursor has no
   width, so the name ends exactly where the static one sits. The key times
   come from a recorded take picked in head.html; the times after each var()
   are a hand-tuned fallback. */
@media (prefers-reduced-motion: no-preference) {
  .intro .masthead-name > span {
    display: inline-block;
    width: 0;
    visibility: hidden;
    animation: type 0s forwards;
  }

  .intro .masthead-name > span:nth-child(1) { animation-delay: var(--key1, 1.20s); }
  .intro .masthead-name > span:nth-child(2) { animation-delay: var(--key2, 1.25s); }
  .intro .masthead-name > span:nth-child(3) { animation-delay: var(--key3, 1.32s); }
  .intro .masthead-name > span:nth-child(4) { animation-delay: var(--key4, 1.36s); }
  .intro .masthead-name > span:nth-child(5) { animation-delay: var(--key5, 1.44s); }
  .intro .masthead-name > span:nth-child(6) { animation-delay: var(--key6, 1.58s); }
  .intro .masthead-name > span:nth-child(7) { animation-delay: var(--key7, 1.71s); }
  .intro .masthead-name > span:nth-child(8) { animation-delay: var(--key8, 2.06s); }
  .intro .masthead-name > span:nth-child(9) { animation-delay: var(--key9, 2.41s); }
  .intro .masthead-name > span:nth-child(10) { animation-delay: var(--key10, 2.53s); }
  .intro .masthead-name > span:nth-child(11) { animation-delay: var(--key11, 2.66s); }

  .intro .masthead-name::after {
    content: "";
    display: inline-block;
    width: 0;
    height: 1em;
    vertical-align: -0.15em;
    box-shadow: 0 0 0 1px currentColor;
    animation: blink 0.4s step-end infinite, gone 0s var(--cursor-gone, 3.6s) forwards; /* ~1s after the last key */
  }
}

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

@keyframes type {
  to { visibility: visible; width: 1ch; }
}

@keyframes gone {
  to { visibility: hidden; }
}

.masthead-nav {
  padding: 0.4rem 0;
  border-block: 2px solid var(--rule);
  font: 0.875rem/1.5 var(--mono);
}

.masthead-nav a {
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.masthead-nav a + a::before {
  content: "·";
  margin-inline: 0.25em;
  color: var(--muted);
}

/* The current page is wrapped in braces. Every link reserves room for them,
   so revealing them never shifts the menu. */
.masthead-nav a span::before,
.masthead-nav a span::after {
  color: var(--muted);
  visibility: hidden;
}

.masthead-nav a span::before {
  content: "{ ";
}

.masthead-nav a span::after {
  content: " }";
}

.masthead-nav a[aria-current="page"] span::before,
.masthead-nav a[aria-current="page"] span::after {
  visibility: visible;
}

/* ---- Text ---- */

main {
  padding-top: 2.5rem;
}

h1,
h2,
h3 {
  font-family: var(--mono);
  line-height: 1.3;
}

h1 {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
}

h2 {
  margin: 2.5rem 0 0.75rem;
  font-size: 1.1rem;
}

h3 {
  margin: 2rem 0 0.5rem;
  font-size: 1rem;
}

/* Resume-style section label: bold capitals with a colon. */
.label {
  font: 700 0.85rem/1.5 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.label::after {
  content: ":";
}

.lede {
  font-size: 1.2rem;
  line-height: 1.55;
}

.meta {
  margin: 0 0 2rem;
  color: var(--muted);
  font: italic 0.85rem/1.5 var(--mono);
}

ul,
ol {
  padding-left: 1.25rem;
}

li::marker {
  color: var(--muted);
}

blockquote {
  margin: 1.75rem 0;
  padding-left: 1rem;
  border-left: 1px solid var(--hairline);
  color: var(--muted);
}

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

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

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

code {
  padding: 0.1em 0.3em;
  background: var(--code-bg);
  font-size: 0.875em;
}

pre {
  overflow-x: auto;
  margin: 1.75rem 0;
  padding: 1rem 1.25rem;
  border-left: 3px solid var(--rule);
  background: var(--code-bg);
  font-size: 0.85rem;
  line-height: 1.55;
}

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

/* ---- Fact list: labels in a left column, like the resume summary ---- */

.facts {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.4rem 1rem;
  margin: 2rem 0;
}

.facts dt {
  font: 700 0.85rem/1.95 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.facts dt::after {
  content: ":";
}

.facts dd {
  margin: 0;
}

/* ---- Entry list: title left, date right ---- */

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

.entries li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--hairline);
}

.entries .summary {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Trail back up from a project page or sub-page. */
.breadcrumb {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font: 0.8rem/1.5 var(--mono);
}

/* ---- Resume ---- */

/* Section labels are the resume's main headings, so they're larger here. */
.resume .facts {
  grid-template-columns: 9rem 1fr;
  margin-top: 0;
}

.resume .facts dt,
.resume .label {
  font-size: 1rem;
  line-height: 1.75;
}

.job {
  margin: 1.75rem 0;
}

.job h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 400;
  font-variant-caps: small-caps;
  letter-spacing: 0.02em;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.role {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 1rem;
  margin: 1rem 0 0.25rem;
  font: 0.95rem/1.5 var(--mono);
}

.job h3 + .role {
  margin-top: 0.25rem;
}

.job ul {
  margin: 0.25rem 0 0;
}

.job li + li {
  margin-top: 0.35rem;
}

.job > p:not(.role) {
  margin: 0.25rem 0 0;
}

.entries time,
.date {
  color: var(--muted);
  font: italic 0.85rem/1.5 var(--mono);
  white-space: nowrap;
}

/* ---- Figures: images, diagrams, video ---- */

figure {
  margin: 2.25rem 0;
}

figure img,
figure svg,
figure video {
  display: block;
  width: 100%;
  height: auto;
}

figcaption {
  margin-top: 0.6rem;
  color: var(--muted);
  font: 0.8rem/1.5 var(--mono);
}

.video-placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  border: 1px dashed var(--muted);
  color: var(--muted);
  font: 0.85rem var(--mono);
}

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

.colophon {
  margin-top: 4rem;
  padding: 1.25rem 0 3rem;
  border-top: 2px solid var(--rule);
  color: var(--muted);
  font: 0.8rem/1.5 var(--mono);
  text-align: center;
}

.colophon p {
  margin: 0.25rem 0;
}

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

@media (max-width: 30rem) {
  .facts {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .facts dd {
    margin-bottom: 0.75rem;
  }

  .entries li {
    flex-direction: column;
    gap: 0;
  }
}
