/* ==========================================================================
   Martyn Fagg — personal site
   Editorial-modern: warm paper, blue-black ink, confident cobalt accent.
   ========================================================================== */

:root {
  --paper:      #FBFAF6;
  --paper-2:    #F3F1E9;
  --ink:        #14171E;
  --ink-2:      #40454F;
  --ink-3:      #6C727C;
  --hairline:   #E3DFD3;
  --accent:     #2440E6;   /* cobalt */
  --accent-ink: #16296f;

  --measure: 66ch;
  --pad: clamp(1.25rem, 5vw, 4.5rem);
  --maxw: 1200px;

  --font-display: "Bricolage Grotesque", Georgia, serif;
  --font-body: "Instrument Sans", -apple-system, BlinkMacSystemFont, sans-serif;

  --step--1: clamp(0.83rem, 0.79rem + 0.18vw, 0.94rem);
  --step-0:  clamp(1rem, 0.95rem + 0.25vw, 1.15rem);
  --step-1:  clamp(1.2rem, 1.1rem + 0.5vw, 1.5rem);
  --step-2:  clamp(1.5rem, 1.3rem + 1vw, 2.1rem);
  --step-3:  clamp(2rem, 1.6rem + 2vw, 3.2rem);
  --step-4:  clamp(2.8rem, 2rem + 4vw, 5.6rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:    #101318;
    --paper-2:  #171b22;
    --ink:      #F1EEE6;
    --ink-2:    #B9BCC4;
    --ink-3:    #878C96;
    --hairline: #2A2F38;
    --accent:   #7C93FF;
    --accent-ink: #AEBEFF;
  }
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  font-feature-settings: "ss01", "cv01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* subtle paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.4;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0 0 0.5em;
  font-variation-settings: "opsz" 40;
}

p { margin: 0 0 1.2em; max-width: var(--measure); }

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

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

.wrap { max-width: var(--maxw); margin-inline: auto; padding-inline: var(--pad); }

.eyebrow {
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 600;
  color: var(--ink-3);
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
}
.eyebrow::before {
  content: "";
  width: 1.6em; height: 1px;
  background: var(--accent);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-weight: 600;
  font-size: var(--step--1);
  letter-spacing: 0.01em;
  padding: 0.85em 1.4em;
  border-radius: 100px;
  text-decoration: none;
  transition: transform .18s ease, background .18s ease, color .18s ease;
}
.btn--primary { background: var(--ink); color: var(--paper); }
.btn--primary:hover { background: var(--accent); transform: translateY(-2px); }
.btn--ghost { border: 1px solid var(--hairline); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ink); transform: translateY(-2px); }
.btn svg { width: 1.05em; height: 1.05em; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(1.4) blur(10px);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  border-bottom: 1px solid var(--hairline);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 1rem;
}
.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
  gap: 0.5ch;
}
.brand .dot { color: var(--accent); }
.nav { display: flex; gap: clamp(1rem, 3vw, 2.2rem); align-items: center; }
.nav a {
  text-decoration: none;
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-2);
  position: relative;
}
.nav a:hover { color: var(--ink); }
.nav a::after {
  content: "";
  position: absolute; left: 0; bottom: -4px;
  width: 0; height: 1.5px; background: var(--accent);
  transition: width .2s ease;
}
.nav a:hover::after { width: 100%; }
.nav .nav-cta { display: none; }
@media (min-width: 640px) { .nav .nav-cta { display: inline-flex; } }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(3.5rem, 10vw, 7rem) clamp(2.5rem, 6vw, 4.5rem); }
.hero__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(2rem, 5vw, 4rem);
  align-items: end;
}
@media (min-width: 900px) {
  .hero__grid { grid-template-columns: 1.5fr 0.9fr; }
}
.hero h1 {
  font-size: var(--step-4);
  margin-top: 0.6rem;
  font-variation-settings: "opsz" 48;
}
.hero h1 .accent { color: var(--accent); }
.hero__lead {
  font-size: var(--step-1);
  color: var(--ink-2);
  max-width: 32ch;
  line-height: 1.4;
  margin-top: 1.4rem;
}
.hero__actions { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 2rem; }

.portrait {
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(145deg, var(--paper-2), color-mix(in srgb, var(--accent) 12%, var(--paper-2)));
  border: 1px solid var(--hairline);
  position: relative;
  display: grid;
  place-items: center;
}
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait__ph {
  text-align: center; color: var(--ink-3); padding: 1.5rem;
  font-size: var(--step--1);
}
.portrait__ph strong { display: block; font-family: var(--font-display); font-size: 2.4rem; color: var(--ink-2); margin-bottom: .3rem; }

/* ---------- Section scaffolding ---------- */
.section { padding-block: clamp(3rem, 8vw, 6rem); border-top: 1px solid var(--hairline); }
.section__head {
  display: grid;
  gap: 0.4rem;
  margin-bottom: clamp(2rem, 5vw, 3.5rem);
}
.section__head h2 { font-size: var(--step-3); }
.section__num {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* ---------- Roles index ---------- */
.roles { display: grid; gap: 0; }
.role {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem 2rem;
  padding: clamp(1.4rem, 3vw, 2.1rem) 0;
  border-top: 1px solid var(--hairline);
  transition: padding-left .25s ease;
}
.role:last-child { border-bottom: 1px solid var(--hairline); }
.role:hover { padding-left: 0.75rem; }
@media (min-width: 760px) {
  .role { grid-template-columns: 0.35fr 1.2fr 0.5fr; align-items: baseline; }
}
.role__org { font-family: var(--font-display); font-size: var(--step-2); font-weight: 600; }
.role__org a { text-decoration: none; }
.role__org a:hover { color: var(--accent); }
.role__role { color: var(--ink-2); font-size: var(--step-0); }
.role__role .sub { display:block; color: var(--ink-3); font-size: var(--step--1); margin-top: .35rem; }
.role__meta { color: var(--ink-3); font-size: var(--step--1); font-variant-numeric: tabular-nums; }
@media (min-width: 760px) { .role__meta { text-align: right; } }

/* ---------- About ---------- */
.about__grid { display: grid; gap: clamp(1.5rem,4vw,3rem); }
@media (min-width: 820px) { .about__grid { grid-template-columns: 0.8fr 1.2fr; } }
.about__lead { font-family: var(--font-display); font-size: var(--step-2); line-height: 1.2; font-weight: 500; }
.about__body p { color: var(--ink-2); }

/* ---------- Writing list ---------- */
.posts { display: grid; gap: 0; }
.post-card {
  display: grid;
  gap: 0.5rem 2rem;
  padding: clamp(1.5rem, 3.5vw, 2.4rem) 0;
  border-top: 1px solid var(--hairline);
  text-decoration: none;
  color: inherit;
  transition: padding-left .25s ease;
}
.posts .post-card:last-child { border-bottom: 1px solid var(--hairline); }
.post-card:hover { padding-left: 0.75rem; }
@media (min-width: 720px) {
  .post-card { grid-template-columns: 0.4fr 1.6fr; align-items: baseline; }
}
.post-card__date { color: var(--ink-3); font-size: var(--step--1); font-variant-numeric: tabular-nums; }
.post-card__title { font-family: var(--font-display); font-size: var(--step-2); font-weight: 600; line-height: 1.1; margin: 0; }
.post-card:hover .post-card__title { color: var(--accent); }
.post-card__excerpt { color: var(--ink-2); margin: 0.5rem 0 0; font-size: var(--step-0); }
.post-card__more { display:inline-flex; align-items:center; gap:.4em; margin-top:.7rem; font-size: var(--step--1); font-weight:600; color: var(--accent); }

.empty-note { color: var(--ink-3); font-style: italic; }

/* ---------- Connect / CTA band ---------- */
.connect { background: var(--ink); color: var(--paper); border: 0; }
.connect .section__num { color: var(--accent); }
.connect h2 { color: var(--paper); font-size: var(--step-3); }
.connect p { color: color-mix(in srgb, var(--paper) 75%, transparent); }
.connect .btn--primary { background: var(--paper); color: var(--ink); }
.connect .btn--primary:hover { background: var(--accent); color: #fff; }
.connect .btn--ghost { border-color: color-mix(in srgb, var(--paper) 30%, transparent); color: var(--paper); }
.connect .btn--ghost:hover { border-color: var(--paper); }

/* ---------- Name note (colophon) ---------- */
.namenote {
  border-top: 1px solid var(--hairline);
  padding-block: clamp(2rem, 5vw, 3rem);
}
.namenote .wrap {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 4vw, 2.4rem);
  flex-wrap: wrap;
}
.namenote__glyph {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.4rem);
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
  flex: none;
}
.namenote__glyph .phi { color: var(--accent); }
.namenote__text { max-width: 52ch; }
.namenote__text p { margin: 0; color: var(--ink-3); font-size: var(--step--1); line-height: 1.6; }
.namenote__text .say { color: var(--ink-2); font-weight: 600; }
.namenote__text .say b { color: var(--ink); font-weight: 600; }
.namenote__text .not { font-style: italic; }

/* ---------- Footer ---------- */
.site-footer {
  padding-block: 2.5rem;
  border-top: 1px solid var(--hairline);
  color: var(--ink-3);
  font-size: var(--step--1);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* ---------- Article (blog post) ---------- */
.article { padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(3rem,8vw,6rem); }
.article__head { max-width: 40ch; margin-bottom: clamp(2rem,5vw,3.5rem); }
.article__head h1 { font-size: var(--step-3); margin-top: .8rem; }
.article__meta { color: var(--ink-3); font-size: var(--step--1); margin-top: 1rem; display:flex; gap: 1rem; flex-wrap: wrap; }
.prose { max-width: var(--measure); }
.prose > * { margin-inline: 0; }
.prose h2 { font-size: var(--step-2); margin-top: 2.2em; }
.prose h3 { font-size: var(--step-1); margin-top: 1.8em; }
.prose p, .prose li { color: var(--ink-2); font-size: var(--step-1); line-height: 1.65; }
.prose a { text-decoration-color: var(--accent); color: var(--accent-ink); }
.prose blockquote {
  margin: 2em 0; padding-left: 1.4rem;
  border-left: 3px solid var(--accent);
  font-family: var(--font-display); font-size: var(--step-1);
  font-style: normal; color: var(--ink);
}
.prose code { background: var(--paper-2); padding: .12em .4em; border-radius: 4px; font-size: .9em; }
.prose pre { background: var(--paper-2); padding: 1.2rem; border-radius: 8px; overflow-x: auto; border: 1px solid var(--hairline); }
.prose pre code { background: none; padding: 0; }
.prose img { max-width: 100%; height: auto; border-radius: 8px; }
.prose hr { border: 0; border-top: 1px solid var(--hairline); margin: 2.5em 0; }
.back-link { display:inline-flex; align-items:center; gap:.4em; font-size: var(--step--1); font-weight:600; text-decoration:none; color: var(--ink-2); }
.back-link:hover { color: var(--accent); }

/* ---------- Page header (writing index) ---------- */
.page-head { padding-block: clamp(3rem,8vw,5rem) clamp(1.5rem,4vw,2.5rem); }
.page-head h1 { font-size: var(--step-4); font-variation-settings: "opsz" 48; }
.page-head p { font-size: var(--step-1); color: var(--ink-2); max-width: 44ch; margin-top: 1rem; }

/* ---------- Entrance animation ---------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal { opacity: 0; transform: translateY(14px); animation: rise .7s cubic-bezier(.2,.7,.2,1) forwards; }
  .reveal[data-d="1"] { animation-delay: .08s; }
  .reveal[data-d="2"] { animation-delay: .16s; }
  .reveal[data-d="3"] { animation-delay: .24s; }
  .reveal[data-d="4"] { animation-delay: .32s; }
  @keyframes rise { to { opacity: 1; transform: none; } }
}

/* focus */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }
.skip { position:absolute; left:-999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--ink); color: var(--paper); padding:.6em 1em; border-radius:6px; z-index:100; }
