/* =========================================================
   Portfolio stylesheet
   Colours live in the variables below (light first, then dark).
   ========================================================= */

@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/plexmono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("../fonts/plexmono-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  --bg: #fbfbf9;
  --bg-alt: #f2f1ec;
  --text: #171716;
  --muted: #55544e;
  --rule: #dddcd5;
  --accent: #d6411b;          /* vermilion — try #1f7a5c (green) or #6d4cd6 (violet) */
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --page: 1040px;
  --measure: 680px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #131312;
  --bg-alt: #1b1b19;
  --text: #ebeae4;
  --muted: #b3b2aa;
  --rule: #2e2e2a;
  --accent: #ff7148;
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--accent); }

h1, h2, h3 { font-weight: 500; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }

strong { font-weight: 600; }
code { font-family: var(--mono); font-size: 0.8em; }

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

.wrap { max-width: var(--page); margin: 0 auto; padding: 0 32px; }

/* Numbers (01, Fig. 1) are the only monospace text */
.num { font-family: var(--mono); font-size: 13px; color: var(--accent); letter-spacing: 0; }

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 28px;
  padding-bottom: 28px;
  font-family: var(--mono);
  font-size: 13px;
}
.masthead .name { text-decoration: none; font-weight: 500; }
.masthead .name::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 10px;
  background: var(--accent);
}

.theme-toggle {
  font: inherit;
  color: var(--text);
  background: none;
  border: 1px solid var(--rule);
  padding: 5px 12px;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--text); }

/* ---------- Home: intro ---------- */
.intro { padding-top: 72px; padding-bottom: 64px; }
.intro h1 { font-size: clamp(2.4rem, 6vw, 4.2rem); max-width: 15ch; }
.intro h1 em { color: var(--accent); }

/* Contents list */
.contents { list-style: none; margin: 48px 0 0; padding: 0; max-width: 560px; }
.contents li { border-top: 1px solid var(--rule); }
.contents li:last-child { border-bottom: 1px solid var(--rule); }
.contents a { display: flex; align-items: baseline; gap: 16px; padding: 9px 0; text-decoration: none; }
.contents .t { flex: 1; }

/* ---------- Home: project entries ---------- */
.intro + .wrap > .entry:first-child { border-top: 1px solid var(--text); }
.entry {
  display: grid;
  grid-template-columns: 96px 1fr;
  padding: 72px 0;
  border-bottom: 1px solid var(--rule);
}
.entry > .num { padding-top: 8px; }
.entry h2 { font-size: clamp(1.8rem, 3.6vw, 2.6rem); margin-bottom: 18px; }
.entry h2 a { text-decoration: none; }
.entry p { max-width: var(--measure); margin: 0 0 16px; }
.entry figure { margin: 0 0 32px; }
.entry video, .entry img { width: 100%; border: 1px solid var(--rule); background: var(--bg-alt); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 28px 0;
  max-width: var(--measure);
  border-top: 1px solid var(--rule);
}
.stats div { padding: 14px 16px 0 0; }
.stats dd { margin: 0; font-size: 1.9rem; line-height: 1.1; }
.stats dt { font-size: 16px; line-height: 1.35; margin-top: 4px; }

.more { font-weight: 500; }

/* ---------- Figures ---------- */
figure { margin: 40px 0; }
figcaption { font-size: 16px; line-height: 1.45; font-style: italic; margin-top: 10px; }
figcaption .num { font-style: normal; margin-right: 6px; }

/* Plots and maps keep their original colours (captions refer to them);
   in dark mode they are only dimmed slightly so they don't glare */
:root[data-theme="dark"] .plot { filter: brightness(0.88); }

/* ---------- Write-up pages ---------- */
.article { padding-top: 56px; padding-bottom: 72px; counter-reset: section fig; }
.back { text-decoration: none; }
.back:hover { text-decoration: underline; text-decoration-color: var(--accent); }

.article-head { margin: 40px 0 0; padding-bottom: 40px; border-bottom: 1px solid var(--text); }
.kicker { font-style: italic; color: var(--accent); margin: 0 0 12px; font-size: 1.15rem; }
.article-head h1 { font-size: clamp(2.6rem, 6vw, 4.2rem); margin-bottom: 24px; }
.article-head .lead { font-size: 1.3rem; line-height: 1.5; max-width: var(--measure); margin: 0; }

/* Text keeps a readable width; figures, diagrams, spec block and videos use the full page width */
.body > * { max-width: var(--measure); }
.body > figure, .body > .pair, .body > .trio, .body > .spec, .body > .chapters { max-width: none; }
.body > p, .body li { margin: 0 0 1em; }
.body ul, .body ol { padding-left: 1.1em; }
.body li::marker { color: var(--accent); }
.body h3 { font-size: 1.3rem; margin: 1.8em 0 0.5em; }

/* Numbered section headings */
.body h2 { counter-increment: section; font-size: 1.7rem; margin: 2.4em 0 0.7em; }
.body h2::before {
  content: counter(section, decimal-leading-zero);
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 0;
}

/* Numbered figure captions */
.body figure { counter-increment: fig; }
.body figcaption::before {
  content: "Fig. " counter(fig);
  font-family: var(--mono);
  font-size: 13px;
  font-style: normal;
  color: var(--accent);
  margin-right: 8px;
}
.body figure img, .body figure video { border: 1px solid var(--rule); background: var(--bg-alt); width: 100%; }

/* Spec block, styled like a drawing's title block */
.spec { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--text); margin: 48px 0 0; }
.spec div { padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.spec div:nth-child(odd) { border-right: 1px solid var(--rule); }
.spec div:nth-last-child(-n+2) { border-bottom: 0; }
.spec dt { font-style: italic; font-size: 16px; }
.spec dd { margin: 2px 0 0; font-size: 18px; line-height: 1.4; }

/* Equations */
.eq {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.9;
  border-left: 2px solid var(--accent);
  padding: 6px 0 6px 20px;
  margin: 24px 0 28px;
  overflow-x: auto;
  white-space: pre;
}

/* Tables */
.data { width: 100%; border-collapse: collapse; margin: 24px 0 32px; font-size: 17px; }
.data th, .data td { text-align: left; padding: 10px 14px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.data thead th { font-weight: 600; border-bottom: 1px solid var(--text); }
.data tbody th { font-weight: 400; font-style: italic; }
.data .win { color: var(--accent); font-weight: 600; }
.table-scroll { overflow-x: auto; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 40px 0; }
.pair figure { margin: 0; }
.trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 40px 0; }
.trio figure { margin: 0; }

/* Chapter list on the project overview */
.chapters { list-style: none; padding: 0; margin: 32px 0 0; border-top: 1px solid var(--text); }
.chapters li { display: grid; grid-template-columns: 96px 1fr; padding: 28px 0; border-bottom: 1px solid var(--rule); }
.chapters li > .num { padding-top: 8px; }
.chapters h3 { font-size: 1.6rem; margin: 0 0 8px; }
.chapters h3 a { text-decoration: none; }
.chapters p { margin: 0; max-width: var(--measure); }

/* Previous / next at the bottom of chapter pages */
.pager { display: flex; justify-content: space-between; gap: 24px; margin-top: 72px; padding-top: 24px; border-top: 1px solid var(--text); }
.pager a { text-decoration: none; display: block; max-width: 45%; }
.pager a:hover .pt { text-decoration: underline; text-decoration-color: var(--accent); }
.pager .pt { font-size: 1.3rem; display: block; }
.pager .next { text-align: right; margin-left: auto; }

/* ---------- Diagrams (inline SVG) ---------- */
.diagram { overflow-x: auto; border: 1px solid var(--rule); background: var(--bg); padding: 12px; }
.diagram svg { display: block; width: 100%; min-width: 640px; height: auto; font-family: var(--serif); }
.diagram .box { fill: var(--bg); stroke: var(--text); stroke-width: 1.2; }
.diagram .box.hl { stroke: var(--accent); stroke-width: 2.2; }
.diagram .box.ext { stroke-dasharray: 5 4; }
.diagram .wire { fill: none; stroke: var(--text); stroke-width: 1.2; }
.diagram .guide { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.diagram .link { fill: none; stroke: var(--text); stroke-width: 7; stroke-linecap: round; }
.diagram .path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.diagram .ink { fill: var(--text); }
.diagram .acc { fill: var(--accent); }
.diagram .band { fill: var(--accent); opacity: 0.13; }
.diagram .joint { fill: var(--bg); stroke: var(--accent); stroke-width: 2.5; }
.diagram .frame { fill: none; stroke: var(--rule); }
.diagram text { fill: var(--text); font-size: 15px; }
.diagram .t { font-size: 15px; font-weight: 600; text-anchor: middle; }
.diagram .s { font-size: 13px; font-style: italic; text-anchor: middle; }
.diagram .lbl { font-family: var(--mono); font-size: 11px; fill: var(--accent); }
.diagram .mid { text-anchor: middle; }
.diagram .end { text-anchor: end; }

/* ---------- Footer ---------- */
.site-footer { display: flex; justify-content: space-between; padding-top: 32px; padding-bottom: 48px; font-size: 16px; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  body { font-size: 18px; }
  .wrap { padding: 0 16px; }
  .intro { padding-top: 40px; padding-bottom: 48px; }
  .entry, .chapters li { grid-template-columns: 1fr; }
  .entry { padding: 48px 0; }
  .entry > .num, .chapters li > .num { padding: 0 0 8px; }
  .stats dd { font-size: 1.45rem; }
  .stats dt { font-size: 14px; }
  .spec { grid-template-columns: 1fr; }
  .spec div:nth-child(odd) { border-right: 0; }
  .spec div:nth-last-child(2) { border-bottom: 1px solid var(--rule); }
  .pair { grid-template-columns: 1fr; gap: 24px; }
  .trio { grid-template-columns: 1fr 1fr; gap: 12px; }
  .data { font-size: 15px; }
  .eq { font-size: 13px; }
  .pager { flex-direction: column; }
  .pager a { max-width: none; }
}

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